


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






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		Any       ,  SCREAMING_SNAKE_CASE_   :		List[Any]       ,  SCREAMING_SNAKE_CASE_   :		List[str]       ,  SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




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

			UpperCamelCase  ,  UpperCamelCase         =					0, 0
			UpperCamelCase         =					n - i

			UpperCamelCase         =					memo.get(SCREAMING_SNAKE_CASE_	)

			if sub_memo is not None:
						UpperCamelCase         =					sub_memo.get(SCREAMING_SNAKE_CASE_	)

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

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

			UpperCamelCase         =					sub_memo[c]

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

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






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		List[str]       ,  SCREAMING_SNAKE_CASE_   :		Optional[Any]       ,  SCREAMING_SNAKE_CASE_   :		int       ,  SCREAMING_SNAKE_CASE_   :		Optional[int]	):





			"""simple docstring"""




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

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

									ds_c += a_i[j]

						if addend > 0:
									break

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






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		Tuple       ,  SCREAMING_SNAKE_CASE_   :		Any       ,  SCREAMING_SNAKE_CASE_   :		Dict	):





			"""simple docstring"""




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

						if addend == 0:
									break

			while addend > 0:
						UpperCamelCase  ,  UpperCamelCase         =					divmod(SCREAMING_SNAKE_CASE_       ,  10	)
						digits.append(SCREAMING_SNAKE_CASE_	)






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int = 10**15	):





			"""simple docstring"""




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

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


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








import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
			from PIL import Image

			from transformers import OwlViTImageProcessor, OwlViTProcessor




@require_vision
class    UpperCAmelCase					(       unittest.TestCase    ):




			def   lowerCamelCase_					(						self							:		Optional[Any]						):







						"""simple docstring"""







						UpperCamelCase         =					tempfile.mkdtemp()

						# fmt: off
						UpperCamelCase         =					["""""", """l""", """o""", """w""", """e""", """r""", """s""", """t""", """i""", """d""", """n""", """lo""", """l</w>""", """w</w>""", """r</w>""", """t</w>""", """low</w>""", """er</w>""", """lowest</w>""", """newer</w>""", """wider""", """<unk>""", """<|startoftext|>""", """<|endoftext|>"""]
						# fmt: on
						UpperCamelCase         =					dict(zip(__magic_name__       ,       range(len(__magic_name__						)						)						)						)
						UpperCamelCase         =					["""#version: 0.2""", """l o""", """lo w</w>""", """e r</w>""", """"""]
						UpperCamelCase         =					{"""unk_token""": """<unk>"""}

						UpperCamelCase         =					os.path.join(self.tmpdirname       ,       VOCAB_FILES_NAMES["""vocab_file"""]						)
						UpperCamelCase         =					os.path.join(self.tmpdirname       ,       VOCAB_FILES_NAMES["""merges_file"""]						)
						with open(self.vocab_file       ,       """w"""       ,       encoding="""utf-8"""						) as fp:
									fp.write(json.dumps(__magic_name__						) + """\n"""						)
						with open(self.merges_file       ,       """w"""       ,       encoding="""utf-8"""						) as fp:
									fp.write("""\n""".join(__magic_name__						)						)

						UpperCamelCase         =					{
						    """do_resize""": True,
						    """size""": 2_0,
						    """do_center_crop""": True,
						    """crop_size""": 1_8,
						    """do_normalize""": True,
						    """image_mean""": [0.48_145_466, 0.4_578_275, 0.40_821_073],
						    """image_std""": [0.26_862_954, 0.26_130_258, 0.27_577_711],
						}
						UpperCamelCase         =					os.path.join(self.tmpdirname       ,       __magic_name__						)
						with open(self.image_processor_file       ,       """w"""       ,       encoding="""utf-8"""						) as fp:
									json.dump(__magic_name__       ,       __magic_name__						)




			def   lowerCamelCase_					(						self							:		str       ,       **__magic_name__							:		Tuple						):







						"""simple docstring"""







						return CLIPTokenizer.from_pretrained(self.tmpdirname       ,       pad_token="""!"""       ,       **__magic_name__						)




			def   lowerCamelCase_					(						self							:		Optional[int]       ,       **__magic_name__							:		str						):







						"""simple docstring"""







						return CLIPTokenizerFast.from_pretrained(self.tmpdirname       ,       pad_token="""!"""       ,       **__magic_name__						)




			def   lowerCamelCase_					(						self							:		Optional[int]       ,       **__magic_name__							:		Optional[Any]						):







						"""simple docstring"""







						return OwlViTImageProcessor.from_pretrained(self.tmpdirname       ,       **__magic_name__						)




			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						shutil.rmtree(self.tmpdirname						)




			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						UpperCamelCase         =					[np.random.randint(2_5_5       ,       size=(3, 3_0, 4_0_0)       ,       dtype=np.uinta						)]

						UpperCamelCase         =					[Image.fromarray(np.moveaxis(__magic_name__       ,       0       ,       -1						)						) for x in image_inputs]

						return image_inputs




			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_tokenizer()
						UpperCamelCase         =					self.get_rust_tokenizer()
						UpperCamelCase         =					self.get_image_processor()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)
						processor_slow.save_pretrained(self.tmpdirname						)
						UpperCamelCase         =					OwlViTProcessor.from_pretrained(self.tmpdirname       ,       use_fast=__magic_name__						)

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)
						processor_fast.save_pretrained(self.tmpdirname						)
						UpperCamelCase         =					OwlViTProcessor.from_pretrained(self.tmpdirname						)

						self.assertEqual(processor_slow.tokenizer.get_vocab()       ,       tokenizer_slow.get_vocab()						)
						self.assertEqual(processor_fast.tokenizer.get_vocab()       ,       tokenizer_fast.get_vocab()						)
						self.assertEqual(tokenizer_slow.get_vocab()       ,       tokenizer_fast.get_vocab()						)
						self.assertIsInstance(processor_slow.tokenizer       ,       __magic_name__						)
						self.assertIsInstance(processor_fast.tokenizer       ,       __magic_name__						)

						self.assertEqual(processor_slow.image_processor.to_json_string()       ,       image_processor.to_json_string()						)
						self.assertEqual(processor_fast.image_processor.to_json_string()       ,       image_processor.to_json_string()						)
						self.assertIsInstance(processor_slow.image_processor       ,       __magic_name__						)
						self.assertIsInstance(processor_fast.image_processor       ,       __magic_name__						)




			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						UpperCamelCase         =					OwlViTProcessor(tokenizer=self.get_tokenizer()       ,       image_processor=self.get_image_processor()						)
						processor.save_pretrained(self.tmpdirname						)

						UpperCamelCase         =					self.get_tokenizer(bos_token="""(BOS)"""       ,       eos_token="""(EOS)"""						)
						UpperCamelCase         =					self.get_image_processor(do_normalize=__magic_name__						)

						UpperCamelCase         =					OwlViTProcessor.from_pretrained(
						    self.tmpdirname       ,       bos_token="""(BOS)"""       ,       eos_token="""(EOS)"""       ,       do_normalize=__magic_name__						)

						self.assertEqual(processor.tokenizer.get_vocab()       ,       tokenizer_add_kwargs.get_vocab()						)
						self.assertIsInstance(processor.tokenizer       ,       __magic_name__						)

						self.assertEqual(processor.image_processor.to_json_string()       ,       image_processor_add_kwargs.to_json_string()						)
						self.assertIsInstance(processor.image_processor       ,       __magic_name__						)




			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_image_processor()
						UpperCamelCase         =					self.get_tokenizer()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)

						UpperCamelCase         =					self.prepare_image_inputs()

						UpperCamelCase         =					image_processor(__magic_name__       ,       return_tensors="""np"""						)
						UpperCamelCase         =					processor(images=__magic_name__       ,       return_tensors="""np"""						)

						for key in input_image_proc.keys():
									self.assertAlmostEqual(input_image_proc[key].sum()       ,       input_processor[key].sum()       ,       delta=1e-2						)




			def   lowerCamelCase_					(						self							:		Any						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_image_processor()
						UpperCamelCase         =					self.get_tokenizer()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)

						UpperCamelCase         =					"""lower newer"""

						UpperCamelCase         =					processor(text=__magic_name__       ,       return_tensors="""np"""						)

						UpperCamelCase         =					tokenizer(__magic_name__       ,       return_tensors="""np"""						)

						for key in encoded_tok.keys():
									self.assertListEqual(encoded_tok[key][0].tolist()       ,       encoded_processor[key][0].tolist()						)




			def   lowerCamelCase_					(						self							:		Optional[Any]						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_image_processor()
						UpperCamelCase         =					self.get_tokenizer()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)

						UpperCamelCase         =					"""lower newer"""
						UpperCamelCase         =					self.prepare_image_inputs()

						UpperCamelCase         =					processor(text=__magic_name__       ,       images=__magic_name__						)

						self.assertListEqual(list(inputs.keys()						)       ,       ["""input_ids""", """attention_mask""", """pixel_values"""]						)

						# test if it raises when no input is passed
						with pytest.raises(__magic_name__						):
									processor()




			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						UpperCamelCase         =					"""google/owlvit-base-patch32"""
						UpperCamelCase         =					OwlViTProcessor.from_pretrained(__magic_name__						)

						UpperCamelCase         =					["""cat""", """nasa badge"""]
						UpperCamelCase         =					processor(text=__magic_name__						)

						UpperCamelCase         =					1_6
						self.assertListEqual(list(inputs.keys()						)       ,       ["""input_ids""", """attention_mask"""]						)
						self.assertEqual(inputs["""input_ids"""].shape       ,       (2, seq_length)						)

						# test if it raises when no input is passed
						with pytest.raises(__magic_name__						):
									processor()




			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						UpperCamelCase         =					"""google/owlvit-base-patch32"""
						UpperCamelCase         =					OwlViTProcessor.from_pretrained(__magic_name__						)

						UpperCamelCase         =					[["""cat""", """nasa badge"""], ["""person"""]]
						UpperCamelCase         =					processor(text=__magic_name__						)

						UpperCamelCase         =					1_6
						UpperCamelCase         =					len(__magic_name__						)
						UpperCamelCase         =					max([len(__magic_name__						) for texts in input_texts]						)

						self.assertListEqual(list(inputs.keys()						)       ,       ["""input_ids""", """attention_mask"""]						)
						self.assertEqual(inputs["""input_ids"""].shape       ,       (batch_size * num_max_text_queries, seq_length)						)

						# test if it raises when no input is passed
						with pytest.raises(__magic_name__						):
									processor()




			def   lowerCamelCase_					(						self							:		List[str]						):







						"""simple docstring"""







						UpperCamelCase         =					"""google/owlvit-base-patch32"""
						UpperCamelCase         =					OwlViTProcessor.from_pretrained(__magic_name__						)

						UpperCamelCase         =					["""cat""", """nasa badge"""]
						UpperCamelCase         =					processor(text=__magic_name__						)

						UpperCamelCase         =					1_6
						UpperCamelCase         =					inputs["""input_ids"""]
						UpperCamelCase         =					[
						    [4_9_4_0_6, 2_3_6_8, 4_9_4_0_7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
						    [4_9_4_0_6, 6_8_4_1, 1_1_3_0_1, 4_9_4_0_7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
						]

						self.assertListEqual(list(inputs.keys()						)       ,       ["""input_ids""", """attention_mask"""]						)
						self.assertEqual(inputs["""input_ids"""].shape       ,       (2, seq_length)						)
						self.assertListEqual(list(input_ids[0]						)       ,       predicted_ids[0]						)
						self.assertListEqual(list(input_ids[1]						)       ,       predicted_ids[1]						)




			def   lowerCamelCase_					(						self							:		str						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_image_processor()
						UpperCamelCase         =					self.get_tokenizer()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)

						UpperCamelCase         =					self.prepare_image_inputs()
						UpperCamelCase         =					self.prepare_image_inputs()

						UpperCamelCase         =					processor(images=__magic_name__       ,       query_images=__magic_name__						)

						self.assertListEqual(list(inputs.keys()						)       ,       ["""query_pixel_values""", """pixel_values"""]						)

						# test if it raises when no input is passed
						with pytest.raises(__magic_name__						):
									processor()





			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						UpperCamelCase         =					self.get_image_processor()
						UpperCamelCase         =					self.get_tokenizer()

						UpperCamelCase         =					OwlViTProcessor(tokenizer=__magic_name__       ,       image_processor=__magic_name__						)

						UpperCamelCase         =					[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

						UpperCamelCase         =					processor.batch_decode(__magic_name__						)
						UpperCamelCase         =					tokenizer.batch_decode(__magic_name__						)

						self.assertListEqual(__magic_name__       ,       __magic_name__						)




