






"""simple docstring"""



_UpperCamelCase		:  Union[str, Any]						=		range(2, 2_0 + 1)
_UpperCamelCase		:  Optional[Any]						=		[1_0**k for k in range(ks[-1] + 1)]
_UpperCamelCase		:  dict[int, dict[int, list[list[int]]]]						=		{}
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  Dict		,					__snake_case			:  int		,					__snake_case			:  Optional[int]		,					__snake_case			:  Union[str, Any]    ):





  '''simple docstring'''





  lowercase							    =       sum(a_i[j] for j in range(__lowercase		,					len(__lowercase    )    )    )
  lowercase							    =       sum(a_i[j] * base[j] for j in range(min(len(__lowercase    )		,					__lowercase    )    )    )

  lowercase    ,     lowercase							    =       0, 0
  lowercase							    =       n - i

  lowercase							    =       memo.get(__lowercase    )

  if sub_memo is not None:
    lowercase							    =       sub_memo.get(__lowercase    )

    if jumps is not None and len(__lowercase    ) > 0:
      # find and make the largest jump without going over
      lowercase							    =       -1
      for _k in range(len(__lowercase    ) - 1		,					-1		,					-1    ):
        if jumps[_k][2] <= k and jumps[_k][1] <= max_dn:
          lowercase							    =       _k
          break

      if max_jump >= 0:
        lowercase    ,     lowercase    ,     lowercase							    =       jumps[max_jump]
        # since the difference between jumps is cached, add c
        lowercase							    =       diff + c
        for j in range(min(__lowercase		,					len(__lowercase    )    )    ):
          lowercase    ,     lowercase							    =       divmod(__lowercase		,					10    )
        if new_c > 0:
          add(__lowercase		,					__lowercase		,					__lowercase    )

    else:
      lowercase							    =       []
  else:
    lowercase							    =       {c: []}
    lowercase							    =       sub_memo

  if dn >= max_dn or c + diff >= base[k]:
    return diff, dn

  if k > ks[0]:
    while True:
      # keep doing smaller jumps
      lowercase    ,     lowercase							    =       next_term(__lowercase		,					k - 1		,					i + dn		,					__lowercase    )
      diff += _diff
      dn += terms_jumped

      if dn >= max_dn or c + diff >= base[k]:
        break
  else:
    # would be too small a jump, just compute sequential terms instead
    lowercase    ,     lowercase							    =       compute(__lowercase		,					__lowercase		,					i + dn		,					__lowercase    )
    diff += _diff
    dn += terms_jumped

  lowercase							    =       sub_memo[c]

  # keep jumps sorted by # of terms skipped
  lowercase							    =       0
  while j < len(__lowercase    ):
    if jumps[j][1] > dn:
      break
    j += 1

  # cache the jump for this value digitsum(b) and c
  sub_memo[c].insert(__lowercase		,					(diff, dn, k)    )
  return (diff, dn)
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  Any		,					__snake_case			:  Optional[Any]		,					__snake_case			:  int		,					__snake_case			:  Union[str, Any]    ):





  '''simple docstring'''





  if i >= n:
    return 0, i
  if k > len(__lowercase    ):
    a_i.extend([0 for _ in range(k - len(__lowercase    )    )]    )

  # note: a_i -> b * 10^k + c
  # ds_b -> digitsum(b)
  # ds_c -> digitsum(c)
  lowercase							    =       i
  lowercase    ,     lowercase    ,     lowercase							    =       0, 0, 0
  for j in range(len(__lowercase    )    ):
    if j >= k:
      ds_b += a_i[j]
    else:
      ds_c += a_i[j]

  while i < n:
    i += 1
    lowercase							    =       ds_c + ds_b
    diff += addend
    lowercase							    =       0
    for j in range(__lowercase    ):
      lowercase							    =       a_i[j] + addend
      lowercase    ,     lowercase							    =       divmod(__lowercase		,					10    )

      ds_c += a_i[j]

    if addend > 0:
      break

  if addend > 0:
    add(__lowercase		,					__lowercase		,					__lowercase    )
  return diff, i - start_i
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  List[str]		,					__snake_case			:  Tuple		,					__snake_case			:  int    ):





  '''simple docstring'''





  for j in range(__lowercase		,					len(__lowercase    )    ):
    lowercase							    =       digits[j] + addend
    if s >= 10:
      lowercase    ,     lowercase							    =       divmod(__lowercase		,					10    )
      lowercase							    =       addend // 10 + quotient
    else:
      lowercase							    =       s
      lowercase							    =       addend // 10

    if addend == 0:
      break

  while addend > 0:
    lowercase    ,     lowercase							    =       divmod(__lowercase		,					10    )
    digits.append(__lowercase    )
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  int = 10**15    ):





  '''simple docstring'''





  lowercase							    =       [1]
  lowercase							    =       1
  lowercase							    =       0
  while True:
    lowercase    ,     lowercase							    =       next_term(__lowercase		,					20		,					i + dn		,					__lowercase    )
    dn += terms_jumped
    if dn == n - i:
      break

  lowercase							    =       0
  for j in range(len(__lowercase    )    ):
    a_n += digits[j] * 10**j
  return a_n


if __name__ == "__main__":
    print(F'''{solution() = }''')









'''simple docstring'''




from .integrations import (
    is_optuna_available,
    is_ray_available,
    is_sigopt_available,
    is_wandb_available,
    run_hp_search_optuna,
    run_hp_search_ray,
    run_hp_search_sigopt,
    run_hp_search_wandb,
)
from .trainer_utils import (
    HPSearchBackend,
    default_hp_space_optuna,
    default_hp_space_ray,
    default_hp_space_sigopt,
    default_hp_space_wandb,
)
from .utils import logging


__SCREAMING_SNAKE_CASE     :int       =				logging.get_logger(__name__)







class   A_	:
 _lowerCamelCase  : str
 _lowerCamelCase  : str           =							None




 @staticmethod
 def      lowercase	(					):
      raise NotImplementedError




 def      lowercase	(					self       :    Union[str, Any]	,			snake_case_       :    Optional[int]	,			snake_case_       :    int	,			snake_case_       :    str	,			**snake_case_       :    List[Any]    ):
      raise NotImplementedError




 def      lowercase	(					self       :    Any	,			snake_case_       :    int    ):
      raise NotImplementedError




 def      lowercase	(					self       :    List[str]    ):
      if not self.is_available():
           raise RuntimeError(
               f'You picked the {self.name} backend, but it is not installed. Run {self.pip_install()}.'    )




 @classmethod
 def      lowercase	(					cls       :    List[Any]    ):
      return f'`pip install {cls.pip_package or cls.name}`'







class   A_	(  lowerCAmelCase_			):
 _lowerCamelCase  : int           =							"""optuna"""




 @staticmethod
 def      lowercase	(					):
      return is_optuna_available()




 def      lowercase	(					self       :    List[str]	,			snake_case_       :    Any	,			snake_case_       :    int	,			snake_case_       :    str	,			**snake_case_       :    Tuple    ):
      return run_hp_search_optuna(snake_case_	,			snake_case_	,			snake_case_	,			**snake_case_    )




 def      lowercase	(					self       :    int	,			snake_case_       :    Optional[int]    ):
      return default_hp_space_optuna(snake_case_    )







class   A_	(  lowerCAmelCase_			):
 _lowerCamelCase  : Any           =							"""ray"""
 _lowerCamelCase  : Tuple           =							"""'ray[tune]'"""




 @staticmethod
 def      lowercase	(					):
      return is_ray_available()




 def      lowercase	(					self       :    Optional[Any]	,			snake_case_       :    Any	,			snake_case_       :    int	,			snake_case_       :    str	,			**snake_case_       :    List[str]    ):
      return run_hp_search_ray(snake_case_	,			snake_case_	,			snake_case_	,			**snake_case_    )




 def      lowercase	(					self       :    Any	,			snake_case_       :    str    ):
      return default_hp_space_ray(snake_case_    )







class   A_	(  lowerCAmelCase_			):
 _lowerCamelCase  : int           =							"""sigopt"""




 @staticmethod
 def      lowercase	(					):
      return is_sigopt_available()




 def      lowercase	(					self       :    Any	,			snake_case_       :    int	,			snake_case_       :    int	,			snake_case_       :    str	,			**snake_case_       :    Dict    ):
      return run_hp_search_sigopt(snake_case_	,			snake_case_	,			snake_case_	,			**snake_case_    )




 def      lowercase	(					self       :    Dict	,			snake_case_       :    Optional[Any]    ):
      return default_hp_space_sigopt(snake_case_    )







class   A_	(  lowerCAmelCase_			):
 _lowerCamelCase  : Optional[int]           =							"""wandb"""




 @staticmethod
 def      lowercase	(					):
      return is_wandb_available()




 def      lowercase	(					self       :    Optional[Any]	,			snake_case_       :    Optional[Any]	,			snake_case_       :    int	,			snake_case_       :    str	,			**snake_case_       :    Optional[Any]    ):
      return run_hp_search_wandb(snake_case_	,			snake_case_	,			snake_case_	,			**snake_case_    )




 def      lowercase	(					self       :    Any	,			snake_case_       :    Union[str, Any]    ):
      return default_hp_space_wandb(snake_case_    )





__SCREAMING_SNAKE_CASE     :Dict       =				{
    HPSearchBackend(backend.name): backend for backend in [OptunaBackend, RayTuneBackend, SigOptBackend, WandbBackend]
}
def 	UpperCAmelCase_							(					)		->       str:


     '''simple docstring'''



     _UpperCAmelCase     							=   [backend for backend in ALL_HYPERPARAMETER_SEARCH_BACKENDS.values() if backend.is_available()]
     if len(__lowercase       ) > 0:
          _UpperCAmelCase     							=   available_backends[0].name
          if len(__lowercase       ) > 1:
               logger.info(
                   f'{len(__lowercase       )} hyperparameter search backends available. Using {name} as the default.'       )
          return name
     raise RuntimeError(
         "No hyperparameter search backend available.\n"
         + "\n".join(
             f' - To install {backend.name} run {backend.pip_install()}'
             for backend in ALL_HYPERPARAMETER_SEARCH_BACKENDS.values()       )       )




