






"""simple docstring"""





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




def 	UpperCAmelCase     (		A	:						int     ,				A	:						Tuple     ,				A	:						List[str]     ,				A	:						Tuple       ):

		'''simple docstring'''


		_UpperCAmelCase							 =		sum(a_i[j] for j in range(A     ,				len(A       )       )       )
		_UpperCAmelCase							 =		sum(a_i[j] * base[j] for j in range(min(len(A       )     ,				A       )       )       )

		_UpperCAmelCase ,					_UpperCAmelCase							 =		0, 0
		_UpperCAmelCase							 =		n - i

		_UpperCAmelCase							 =		memo.get(A       )

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

				if jumps is not None and len(A       ) > 0:
						# find and make the largest jump without going over
						_UpperCAmelCase							 =		-1
						for _k in range(len(A       ) - 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(A     ,				len(A       )       )       ):
										_UpperCAmelCase ,					_UpperCAmelCase							 =		divmod(A     ,				10       )
								if new_c > 0:
										add(A     ,				A     ,				A       )

				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(A     ,				k - 1     ,				i + dn     ,				A       )
						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(A     ,				A     ,				i + dn     ,				A       )
				diff += _diff
				dn += terms_jumped

		_UpperCAmelCase							 =		sub_memo[c]

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

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




def 	UpperCAmelCase     (		A	:						Optional[int]     ,				A	:						Any     ,				A	:						Tuple     ,				A	:						Optional[int]       ):

		'''simple docstring'''


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

		# 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(A       )       ):
				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(A       ):
						_UpperCAmelCase							 =		a_i[j] + addend
						_UpperCAmelCase ,					_UpperCAmelCase							 =		divmod(A     ,				10       )

						ds_c += a_i[j]

				if addend > 0:
						break

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




def 	UpperCAmelCase     (		A	:						Tuple     ,				A	:						Dict     ,				A	:						List[Any]       ):

		'''simple docstring'''


		for j in range(A     ,				len(A       )       ):
				_UpperCAmelCase							 =		digits[j] + addend
				if s >= 10:
						_UpperCAmelCase ,					_UpperCAmelCase							 =		divmod(A     ,				10       )
						_UpperCAmelCase							 =		addend // 10 + quotient
				else:
						_UpperCAmelCase							 =		s
						_UpperCAmelCase							 =		addend // 10

				if addend == 0:
						break

		while addend > 0:
				_UpperCAmelCase ,					_UpperCAmelCase							 =		divmod(A     ,				10       )
				digits.append(A       )




def 	UpperCAmelCase     (		A	:						int = 10**15       ):

		'''simple docstring'''


		_UpperCAmelCase							 =		[1]
		_UpperCAmelCase							 =		1
		_UpperCAmelCase							 =		0
		while True:
				_UpperCAmelCase ,					_UpperCAmelCase							 =		next_term(A     ,				20     ,				i + dn     ,				A       )
				dn += terms_jumped
				if dn == n - i:
						break

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


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







"""simple docstring"""





import argparse
import logging
import pickle
from collections import Counter


logging.basicConfig(
    format='''%(asctime)s - %(levelname)s - %(name)s - %(message)s''', datefmt='''%m/%d/%Y %H:%M:%S''', level=logging.INFO
)
lowercase  							=					logging.getLogger(__name__)

if __name__ == "__main__":
					lowercase  							=					argparse.ArgumentParser(
					    description='''Token Counts for smoothing the masking probabilities in MLM (cf XLM/word2vec)'''
					)
					parser.add_argument(
					    '''--data_file''', type=str, default='''data/dump.bert-base-uncased.pickle''', help='''The binarized dataset.'''
					)
					parser.add_argument(
					    '''--token_counts_dump''', type=str, default='''data/token_counts.bert-base-uncased.pickle''', help='''The dump file.'''
					)
					parser.add_argument('''--vocab_size''', default=3_05_22, type=int)
					lowercase  							=					parser.parse_args()

					logger.info(F'''Loading data from {args.data_file}''')
					with open(args.data_file, '''rb''') as fp:
										lowercase  							=					pickle.load(fp)

					logger.info('''Counting occurrences for MLM.''')
					lowercase  							=					Counter()
					for tk_ids in data:
										counter.update(tk_ids)
					lowercase  							=					[0] * args.vocab_size
					for k, v in counter.items():
										lowercase  							=					v

					logger.info(F'''Dump to {args.token_counts_dump}''')
					with open(args.token_counts_dump, '''wb''') as handle:
										pickle.dump(counts, handle, protocol=pickle.HIGHEST_PROTOCOL)


