
"""simple docstring"""

UpperCamelCase			:       Tuple									=				range(2, 2_0 + 1)
UpperCamelCase			:       Dict									=				[1_0**k for k in range(ks[-1] + 1)]
UpperCamelCase			:       dict[int, dict[int, list[list[int]]]]									=				{}






def 							A		(       snake_case   :str       ,      snake_case   :str       ,      snake_case   :Dict       ,      snake_case   :Union[str, Any]	)   ->			Dict:
 __UpperCamelCase       						= sum(a_i[j] for j in range(_UpperCAmelCase       ,      len(_UpperCAmelCase	)	)	)
 __UpperCamelCase       						= sum(a_i[j] * base[j] for j in range(min(len(_UpperCAmelCase	)       ,      _UpperCAmelCase	)	)	)

 __UpperCamelCase						,			__UpperCamelCase       						= 0, 0
 __UpperCamelCase       						= n - i

 __UpperCamelCase       						= memo.get(_UpperCAmelCase	)

 if sub_memo is not None:
  __UpperCamelCase       						= sub_memo.get(_UpperCAmelCase	)

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

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

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

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

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

 __UpperCamelCase       						= sub_memo[c]

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

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






def 							A		(       snake_case   :Any       ,      snake_case   :Optional[Any]       ,      snake_case   :Optional[int]       ,      snake_case   :Optional[Any]	)   ->			int:
 if i >= n:
  return 0, i
 if k > len(_UpperCAmelCase	):
  a_i.extend([0 for _ in range(k - len(_UpperCAmelCase	)	)]	)

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

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

   ds_c += a_i[j]

  if addend > 0:
   break

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






def 							A		(       snake_case   :Tuple       ,      snake_case   :List[Any]       ,      snake_case   :List[Any]	)   ->			str:
 for j in range(_UpperCAmelCase       ,      len(_UpperCAmelCase	)	):
  __UpperCamelCase       						= digits[j] + addend
  if s >= 1_0:
   __UpperCamelCase						,			__UpperCamelCase       						= divmod(_UpperCAmelCase       ,      1_0	)
   __UpperCamelCase       						= addend // 1_0 + quotient
  else:
   __UpperCamelCase       						= s
   __UpperCamelCase       						= addend // 1_0

  if addend == 0:
   break

 while addend > 0:
  __UpperCamelCase						,			__UpperCamelCase       						= divmod(_UpperCAmelCase       ,      1_0	)
  digits.append(_UpperCAmelCase	)






def 							A		(       snake_case   :int = 1_0**1_5	)   ->			Tuple:
 __UpperCamelCase       						= [1]
 __UpperCamelCase       						= 1
 __UpperCamelCase       						= 0
 while True:
  __UpperCamelCase						,			__UpperCamelCase       						= next_term(_UpperCAmelCase       ,      2_0       ,      i + dn       ,      _UpperCAmelCase	)
  dn += terms_jumped
  if dn == n - i:
   break

 __UpperCamelCase       						= 0
 for j in range(len(_UpperCAmelCase	)	):
  a_n += digits[j] * 1_0**j
 return a_n


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





"""simple docstring"""

import importlib
import sys
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

import torch_xla.distributed.xla_multiprocessing as xmp






def 							A		(       )   ->			List[Any]:
 __UpperCamelCase       						= ArgumentParser(
     description=(
         'PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes'
     )	)

 # Optional arguments for the launch helper
 parser.add_argument('--num_cores'       ,      type=snake_case       ,      default=1       ,      help='Number of TPU cores to use (1 or 8).'	)

 # positional
 parser.add_argument(
     'training_script'       ,      type=snake_case       ,      help=(
         'The full path to the single TPU training '
         'program/script to be launched in parallel, '
         'followed by all the arguments for the '
         'training script'
     )       ,      )

 # rest from the training program
 parser.add_argument('training_script_args'       ,      nargs=snake_case	)

 return parser.parse_args()






def 							A		(       )   ->			Optional[int]:
 __UpperCamelCase       						= parse_args()

 # Import training_script as a module.
 __UpperCamelCase       						= Path(args.training_script	)
 sys.path.append(str(script_fpath.parent.resolve()	)	)
 __UpperCamelCase       						= script_fpath.stem
 __UpperCamelCase       						= importlib.import_module(snake_case	)

 # Patch sys.argv
 __UpperCamelCase       						= [args.training_script] + args.training_script_args + ['--tpu_num_cores', str(args.num_cores	)]

 xmp.spawn(mod._mp_fn       ,      args=()       ,      nprocs=args.num_cores	)


if __name__ == "__main__":
      main()



