



UpperCAmelCase_		 =					range(2, 2_0 + 1)
UpperCAmelCase_		 =					[1_0**k for k in range(ks[-1] + 1)]
UpperCAmelCase_		 =					{}

def 	SCREAMING_SNAKE_CASE_							(	_snake_case	:Tuple	,   _snake_case	:List[str]	,   _snake_case	:int	,   _snake_case	:str				)  ->     int:
   _A      =       sum(a_i[j] for j in range(_snake_case	,   len(_snake_case				)				)				)
   _A      =       sum(a_i[j] * base[j] for j in range(min(len(_snake_case				)	,   _snake_case				)				)				)

   _A  ,    _A      =       0, 0
   _A      =       n - i

   _A      =       memo.get(_snake_case				)

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

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

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

      else:
         _A      =       []
   else:
      _A      =       {c: []}
      _A      =       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  ,    _A      =       next_term(_snake_case	,   k - 1	,   i + dn	,   _snake_case				)
         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  ,    _A      =       compute(_snake_case	,   _snake_case	,   i + dn	,   _snake_case				)
      diff += _diff
      dn += terms_jumped

   _A      =       sub_memo[c]

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

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

def 	SCREAMING_SNAKE_CASE_							(	_snake_case	:Union[str, Any]	,   _snake_case	:str	,   _snake_case	:Dict	,   _snake_case	:int				)  ->     Dict:
   if i >= n:
      return 0, i
   if k > len(_snake_case				):
      a_i.extend([0 for _ in range(k - len(_snake_case				)				)]				)

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

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

         ds_c += a_i[j]

      if addend > 0:
         break

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

def 	SCREAMING_SNAKE_CASE_							(	_snake_case	:List[str]	,   _snake_case	:int	,   _snake_case	:Optional[int]				)  ->     str:
   for j in range(_snake_case	,   len(_snake_case				)				):
      _A      =       digits[j] + addend
      if s >= 10:
         _A  ,    _A      =       divmod(_snake_case	,   10				)
         _A      =       addend // 10 + quotient
      else:
         _A      =       s
         _A      =       addend // 10

      if addend == 0:
         break

   while addend > 0:
      _A  ,    _A      =       divmod(_snake_case	,   10				)
      digits.append(_snake_case				)

def 	SCREAMING_SNAKE_CASE_							(	_snake_case	:int = 10**15				)  ->     int:
   _A      =       [1]
   _A      =       1
   _A      =       0
   while True:
      _A  ,    _A      =       next_term(_snake_case	,   20	,   i + dn	,   _snake_case				)
      dn += terms_jumped
      if dn == n - i:
         break

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


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









'''simple docstring'''
import argparse

import torch

from transformers import OpenAIGPTConfig, OpenAIGPTModel, load_tf_weights_in_openai_gpt
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()





def 			lowerCamelCase(							SCREAMING_SNAKE_CASE_       ,SCREAMING_SNAKE_CASE_       ,SCREAMING_SNAKE_CASE_     )		->		str:
			# Construct model
			if openai_config_file == "":
						A_									= OpenAIGPTConfig()
			else:
						A_									= OpenAIGPTConfig.from_json_file(SCREAMING_SNAKE_CASE_     )
			A_									= OpenAIGPTModel(SCREAMING_SNAKE_CASE_     )

			# Load weights from numpy
			load_tf_weights_in_openai_gpt(SCREAMING_SNAKE_CASE_       ,SCREAMING_SNAKE_CASE_       ,SCREAMING_SNAKE_CASE_     )

			# Save pytorch-model
			A_									= pytorch_dump_folder_path + '/' + WEIGHTS_NAME
			A_									= pytorch_dump_folder_path + '/' + CONFIG_NAME
			print(F'Save PyTorch model to {pytorch_weights_dump_path}'     )
			torch.save(model.state_dict()       ,SCREAMING_SNAKE_CASE_     )
			print(F'Save configuration file to {pytorch_config_dump_path}'     )
			with open(SCREAMING_SNAKE_CASE_       ,'w'       ,encoding='utf-8'     ) as f:
						f.write(config.to_json_string()     )


if __name__ == "__main__":
							_SCREAMING_SNAKE_CASE			=						argparse.ArgumentParser()
							# Required parameters
							parser.add_argument(
							    "--openai_checkpoint_folder_path",
							    default=None,
							    type=str,
							    required=True,
							    help="Path to the TensorFlow checkpoint path.",
							)
							parser.add_argument(
							    "--pytorch_dump_folder_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
							)
							parser.add_argument(
							    "--openai_config_file",
							    default="",
							    type=str,
							    help=(
							        "An optional config json file corresponding to the pre-trained OpenAI model. \n"
							        "This specifies the model architecture."
							    ),
							)
							_SCREAMING_SNAKE_CASE			=						parser.parse_args()
							convert_openai_checkpoint_to_pytorch(
							    args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
							)




