


'''simple docstring'''

a_  :				int						= range(2, 20 + 1)
a_  :				List[Any]						= [10**k for k in range(ks[-1] + 1)]
a_  :				dict[int, dict[int, list[list[int]]]]						= {}





def __snake_case					(      UpperCAmelCase_						:						Any					,				UpperCAmelCase_						:						Union[str, Any]					,				UpperCAmelCase_						:						Any					,				UpperCAmelCase_						:						Optional[int]		):
 lowerCamelCase_      =  sum(a_i[j] for j in range(UpperCAmelCase_					,				len(UpperCAmelCase_		)		)		)
 lowerCamelCase_      =  sum(a_i[j] * base[j] for j in range(min(len(UpperCAmelCase_		)					,				UpperCAmelCase_		)		)		)

 lowerCamelCase_      =  0, 0
 lowerCamelCase_      =  n - i

 lowerCamelCase_      =  memo.get(UpperCAmelCase_		)

 if sub_memo is not None:
  lowerCamelCase_      =  sub_memo.get(UpperCAmelCase_		)

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

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

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

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

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

 lowerCamelCase_      =  sub_memo[c]

 # keep jumps sorted by # of terms skipped
 lowerCamelCase_      =  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 __snake_case					(      UpperCAmelCase_						:						Dict					,				UpperCAmelCase_						:						Optional[Any]					,				UpperCAmelCase_						:						List[str]					,				UpperCAmelCase_						:						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)
 lowerCamelCase_      =  i
 lowerCamelCase_      =  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
  lowerCamelCase_      =  ds_c + ds_b
  diff += addend
  lowerCamelCase_      =  0
  for j in range(UpperCAmelCase_		):
   lowerCamelCase_      =  a_i[j] + addend
   lowerCamelCase_      =  divmod(UpperCAmelCase_					,				10		)

   ds_c += a_i[j]

  if addend > 0:
   break

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





def __snake_case					(      UpperCAmelCase_						:						List[Any]					,				UpperCAmelCase_						:						Optional[int]					,				UpperCAmelCase_						:						int		):
 for j in range(UpperCAmelCase_					,				len(UpperCAmelCase_		)		):
  lowerCamelCase_      =  digits[j] + addend
  if s >= 10:
   lowerCamelCase_      =  divmod(UpperCAmelCase_					,				10		)
   lowerCamelCase_      =  addend // 10 + quotient
  else:
   lowerCamelCase_      =  s
   lowerCamelCase_      =  addend // 10

  if addend == 0:
   break

 while addend > 0:
  lowerCamelCase_      =  divmod(UpperCAmelCase_					,				10		)
  digits.append(UpperCAmelCase_		)





def __snake_case					(      UpperCAmelCase_						:						Tuple = 10**15		):
 lowerCamelCase_      =  [1]
 lowerCamelCase_      =  1
 lowerCamelCase_      =  0
 while True:
  lowerCamelCase_      =  next_term(UpperCAmelCase_					,				20					,				i + dn					,				UpperCAmelCase_		)
  dn += terms_jumped
  if dn == n - i:
   break

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


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









from typing import Union

import fire
import torch
from tqdm import tqdm



def 					UpperCAmelCase__     (   lowerCamelCase,	lowerCamelCase = "cpu",	lowerCamelCase = None      ):
  lowercase			:Optional[Any]							=  torch.load(lowerCamelCase,	map_location=lowerCamelCase      )
  for k, v in tqdm(state_dict.items()      ):
    if not isinstance(lowerCamelCase,	torch.Tensor      ):
      raise TypeError("FP16 conversion only works on paths that are saved state dicts, like pytorch_model.bin"      )
    lowercase			:List[Any]							=  v.half()
  if save_path is None:  # overwrite src_path
    lowercase			:Optional[Any]							=  src_path
  torch.save(lowerCamelCase,	lowerCamelCase      )


if __name__ == "__main__":
     fire.Fire(convert)



