


'''simple docstring'''







A				:					Any      						=			range(2, 20 + 1)
A				:					Optional[Any]      						=			[10**k for k in range(ks[-1] + 1)]
A				:					Dict      						=			{}






def 				lowerCAmelCase__	(    lowerCamelCase					:      str  ,lowerCamelCase					:      List[str]  ,lowerCamelCase					:      int  ,lowerCamelCase					:      Tuple       ):
       _A					:     Optional[int]     = sum(a_i[j] for j in range(lowerCAmelCase_  ,len(lowerCAmelCase_       )       )       )
       _A					:     List[str]     = sum(a_i[j] * base[j] for j in range(min(len(lowerCAmelCase_       )  ,lowerCAmelCase_       )       )       )

       _A					:     Any     = 0, 0
       _A					:     Any     = n - i

       _A					:     List[Any]     = memo.get(lowerCAmelCase_       )

       if sub_memo is not None:
              _A					:     Tuple     = sub_memo.get(lowerCAmelCase_       )

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

                     if max_jump >= 0:
                            _A					:     Tuple     = jumps[max_jump]
                            # since the difference between jumps is cached, add c
                            _A					:     Union[str, Any]     = diff + c
                            for j in range(min(lowerCAmelCase_  ,len(lowerCAmelCase_       )       )       ):
                                   _A					:     Dict     = divmod(lowerCAmelCase_  ,10       )
                            if new_c > 0:
                                   add(lowerCAmelCase_  ,lowerCAmelCase_  ,lowerCAmelCase_       )

              else:
                     _A					:     Tuple     = []
       else:
              _A					:     Any     = {c: []}
              _A					:     Optional[Any]     = sub_memo

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

       if k > ks[0]:
              while True:
                     # keep doing smaller jumps
                     _A					:     Dict     = next_term(lowerCAmelCase_  ,k - 1  ,i + dn  ,lowerCAmelCase_       )
                     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
              _A					:     Any     = compute(lowerCAmelCase_  ,lowerCAmelCase_  ,i + dn  ,lowerCAmelCase_       )
              diff += _diff
              dn += terms_jumped

       _A					:     Tuple     = sub_memo[c]

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

       # cache the jump for this value digitsum(b) and c
       sub_memo[c].insert(lowerCAmelCase_  ,(diff, dn, k)       )
       return (diff, dn)






def 				lowerCAmelCase__	(    lowerCamelCase					:      List[Any]  ,lowerCamelCase					:      Union[str, Any]  ,lowerCamelCase					:      Tuple  ,lowerCamelCase					:      Optional[Any]       ):
       if i >= n:
              return 0, i
       if k > len(lowerCAmelCase_       ):
              a_i.extend([0 for _ in range(k - len(lowerCAmelCase_       )       )]       )

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

       while i < n:
              i += 1
              _A					:     Any     = ds_c + ds_b
              diff += addend
              _A					:     int     = 0
              for j in range(lowerCAmelCase_       ):
                     _A					:     Optional[Any]     = a_i[j] + addend
                     _A					:     Tuple     = divmod(lowerCAmelCase_  ,10       )

                     ds_c += a_i[j]

              if addend > 0:
                     break

       if addend > 0:
              add(lowerCAmelCase_  ,lowerCAmelCase_  ,lowerCAmelCase_       )
       return diff, i - start_i






def 				lowerCAmelCase__	(    lowerCamelCase					:      Dict  ,lowerCamelCase					:      Any  ,lowerCamelCase					:      Dict       ):
       for j in range(lowerCAmelCase_  ,len(lowerCAmelCase_       )       ):
              _A					:     Optional[Any]     = digits[j] + addend
              if s >= 10:
                     _A					:     List[str]     = divmod(lowerCAmelCase_  ,10       )
                     _A					:     List[str]     = addend // 10 + quotient
              else:
                     _A					:     Optional[Any]     = s
                     _A					:     Optional[Any]     = addend // 10

              if addend == 0:
                     break

       while addend > 0:
              _A					:     List[str]     = divmod(lowerCAmelCase_  ,10       )
              digits.append(lowerCAmelCase_       )






def 				lowerCAmelCase__	(    lowerCamelCase					:      Dict = 10**15       ):
       _A					:     Dict     = [1]
       _A					:     int     = 1
       _A					:     Tuple     = 0
       while True:
              _A					:     str     = next_term(lowerCAmelCase_  ,20  ,i + dn  ,lowerCAmelCase_       )
              dn += terms_jumped
              if dn == n - i:
                     break

       _A					:     Union[str, Any]     = 0
       for j in range(len(lowerCAmelCase_       )       ):
              a_n += digits[j] * 10**j
       return a_n


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










'''simple docstring'''







import operator as op


A				:					List[str]    						=			'''scaler.pt'''
A				:					Optional[int]    						=			'''pytorch_model'''
A				:					Union[str, Any]    						=			'''random_states'''
A				:					List[Any]    						=			'''optimizer'''
A				:					Optional[Any]    						=			'''scheduler'''
A				:					Optional[int]    						=			'''pytorch_model.bin'''
A				:					List[str]    						=			'''pytorch_model.bin.index.json'''
A				:					List[Any]    						=			'''model.safetensors'''
A				:					int    						=			'''model.safetensors.index.json'''
A				:					List[str]    						=			'''1.10.2'''
A				:					str    						=			'''py38'''
A				:					int    						=			'''4.17.0'''
A				:					Tuple    						=			['''ml.p3.16xlarge''', '''ml.p3dn.24xlarge''', '''ml.p4dn.24xlarge''']
A				:					Union[str, Any]    						=			['''FULL_SHARD''', '''SHARD_GRAD_OP''', '''NO_SHARD''', '''HYBRID_SHARD''', '''HYBRID_SHARD_ZERO2''']
A				:					Optional[Any]    						=			['''TRANSFORMER_BASED_WRAP''', '''SIZE_BASED_WRAP''', '''NO_WRAP''']
A				:					Dict    						=			['''BACKWARD_PRE''', '''BACKWARD_POST''', '''NO_PREFETCH''']
A				:					Any    						=			['''FULL_STATE_DICT''', '''LOCAL_STATE_DICT''', '''SHARDED_STATE_DICT''']
A				:					Tuple    						=			'''2.0.1'''
A				:					List[str]    						=			['''pdsh''', '''standard''', '''openmpi''', '''mvapich''']
A				:					Union[str, Any]    						=			['''default''', '''reduce-overhead''', '''max-autotune''']

A				:					List[Any]    						=			{'''>''': op.gt, '''>=''': op.ge, '''==''': op.eq, '''!=''': op.ne, '''<=''': op.le, '''<''': op.lt}

# These are the args for `torch.distributed.launch` for pytorch < 1.9
A				:					Tuple    						=			[
    '''nnodes''',
    '''nproc_per_node''',
    '''rdzv_backend''',
    '''rdzv_endpoint''',
    '''rdzv_id''',
    '''rdzv_conf''',
    '''standalone''',
    '''max_restarts''',
    '''monitor_interval''',
    '''start_method''',
    '''role''',
    '''module''',
    '''m''',
    '''no_python''',
    '''run_path''',
    '''log_dir''',
    '''r''',
    '''redirects''',
    '''t''',
    '''tee''',
    '''node_rank''',
    '''master_addr''',
    '''master_port''',
]

A				:					List[str]    						=			['''DEEPSPEED''', '''MULTI_GPU''', '''FSDP''', '''MEGATRON_LM''']
A				:					Any    						=			['''DEEPSPEED''', '''MULTI_XPU''', '''FSDP''']






