



'''simple docstring'''

__lowerCAmelCase									=   range(2, 20 + 1)
__lowerCAmelCase									=   [10**k for k in range(ks[-1] + 1)]
__lowerCAmelCase									=   {}



def      __lowerCamelCase     (      lowerCAmelCase_						,			lowerCAmelCase_						,			lowerCAmelCase_						,			lowerCAmelCase_  )			->      Optional[int]:
		_a     :      str        =							sum(a_i[j] for j in range(lowerCAmelCase_						,			len(lowerCAmelCase_  )  )  )
		_a     :      Optional[int]        =							sum(a_i[j] * base[j] for j in range(min(len(lowerCAmelCase_  )						,			lowerCAmelCase_  )  )  )

		_a     :      str        =							0, 0
		_a     :      Tuple        =							n - i

		_a     :      Dict        =							memo.get(lowerCAmelCase_  )

		if sub_memo is not None:
				_a     :      Optional[Any]        =							sub_memo.get(lowerCAmelCase_  )

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

						if max_jump >= 0:
								_a     :      Any        =							jumps[max_jump]
								# since the difference between jumps is cached, add c
								_a     :      str        =							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     :      List[Any]        =							[]
		else:
				_a     :      Optional[Any]        =							{c: []}
				_a     :      Union[str, 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     :      Union[str, Any]        =							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     :      Dict        =							compute(lowerCAmelCase_						,			lowerCAmelCase_						,			i + dn						,			lowerCAmelCase_  )
				diff += _diff
				dn += terms_jumped

		_a     :      Any        =							sub_memo[c]

		# keep jumps sorted by # of terms skipped
		_a     :      str        =							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_						,			lowerCAmelCase_						,			lowerCAmelCase_						,			lowerCAmelCase_  )			->      str:
		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     :      List[Any]        =							i
		_a     :      Any        =							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     :      str        =							ds_c + ds_b
				diff += addend
				_a     :      List[str]        =							0
				for j in range(lowerCAmelCase_  ):
						_a     :      Any        =							a_i[j] + addend
						_a     :      List[Any]        =							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_						,			lowerCAmelCase_						,			lowerCAmelCase_  )			->      int:
		for j in range(lowerCAmelCase_						,			len(lowerCAmelCase_  )  ):
				_a     :      str        =							digits[j] + addend
				if s >= 10:
						_a     :      Any        =							divmod(lowerCAmelCase_						,			10  )
						_a     :      Any        =							addend // 10 + quotient
				else:
						_a     :      Union[str, Any]        =							s
						_a     :      Union[str, Any]        =							addend // 10

				if addend == 0:
						break

		while addend > 0:
				_a     :      Union[str, Any]        =							divmod(lowerCAmelCase_						,			10  )
				digits.append(lowerCAmelCase_  )



def      __lowerCamelCase     (      lowerCAmelCase_ = 10**15  )			->      int:
		_a     :      Optional[Any]        =							[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     :      Dict        =							0
		for j in range(len(lowerCAmelCase_  )  ):
				a_n += digits[j] * 10**j
		return a_n


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








import os
import unittest

from transformers.models.cpmant.tokenization_cpmant import VOCAB_FILES_NAMES, CpmAntTokenizer
from transformers.testing_utils import require_jieba, tooslow

from ...test_tokenization_common import TokenizerTesterMixin





@require_jieba
class   __a			(    __UpperCamelCase       ,       unittest.TestCase      ):
 __lowercase :							str        = CpmAntTokenizer
 __lowercase :							List[Any]        = False
 def 		SCREAMING_SNAKE_CASE__   (   self )					->				str:




        '''simple docstring'''
        super().setUp()

        lowercase__:   Any  			=   [
            '<d>',
            '</d>',
            '<s>',
            '</s>',
            '</_>',
            '<unk>',
            '<pad>',
            '</n>',
            '我',
            '是',
            'C',
            'P',
            'M',
            'A',
            'n',
            't',
        ]
        lowercase__:   List[Any]  			=   os.path.join(self.tmpdirname				, VOCAB_FILES_NAMES['vocab_file'] )
        with open(self.vocab_file				, 'w'				, encoding='utf-8' ) as vocab_writer:
               vocab_writer.write(''.join([x + '\n' for x in vocab_tokens] ) )
 @tooslow
 def 		SCREAMING_SNAKE_CASE__   (   self )					->				Tuple:




        '''simple docstring'''
        lowercase__:   Optional[int]  			=   CpmAntTokenizer.from_pretrained('openbmb/cpm-ant-10b' )
        lowercase__:   Optional[Any]  			=   '今天天气真好！'
        lowercase__:   str  			=   ['今天', '天气', '真', '好', '！']
        lowercase__:   Optional[Any]  			=   tokenizer.tokenize(lowerCAmelCase__ )
        self.assertListEqual(lowerCAmelCase__				, lowerCAmelCase__ )
        lowercase__:   List[str]  			=   '今天天气真好！'
        lowercase__:   List[str]  			=   [tokenizer.bos_token] + tokens

        lowercase__:   Tuple  			=   [6, 9_802, 14_962, 2_082, 831, 244]
        self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCAmelCase__ )				, lowerCAmelCase__ )

        lowercase__:   Any  			=   tokenizer.decode(lowerCAmelCase__ )
        self.assertEqual(lowerCAmelCase__				, lowerCAmelCase__ )


