

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


def     __SCREAMING_SNAKE_CASE   (SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__			):
						snake_case_  =      sum(a_i[j] for j in range(SCREAMING_SNAKE_CASE__    ,						len(SCREAMING_SNAKE_CASE__			)			)			)
						snake_case_  =      sum(a_i[j] * base[j] for j in range(min(len(SCREAMING_SNAKE_CASE__			)    ,						SCREAMING_SNAKE_CASE__			)			)			)

						snake_case_,       snake_case_  =      0, 0
						snake_case_  =      n - i

						snake_case_  =      memo.get(SCREAMING_SNAKE_CASE__			)

						if sub_memo is not None:
												snake_case_  =      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
																		snake_case_  =      -1
																		for _k in range(len(SCREAMING_SNAKE_CASE__			) - 1    ,						-1    ,						-1			):
																								if jumps[_k][2] <= k and jumps[_k][1] <= max_dn:
																														snake_case_  =      _k
																														break

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

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

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

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

						snake_case_  =      sub_memo[c]

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

												if addend == 0:
																		break

						while addend > 0:
												snake_case_,       snake_case_  =      divmod(SCREAMING_SNAKE_CASE__    ,						10			)
												digits.append(SCREAMING_SNAKE_CASE__			)


def     __SCREAMING_SNAKE_CASE   (SCREAMING_SNAKE_CASE__ = 10**15			):
						snake_case_  =      [1]
						snake_case_  =      1
						snake_case_  =      0
						while True:
												snake_case_,       snake_case_  =      next_term(SCREAMING_SNAKE_CASE__    ,						20    ,						i + dn    ,						SCREAMING_SNAKE_CASE__			)
												dn += terms_jumped
												if dn == n - i:
																		break

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


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



'''simple docstring'''






import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible






class    __magic_name__				(						unittest.TestCase							):






       def      lowerCAmelCase						(     self)		->    Union[str, Any]:




          '''simple docstring'''
          _UpperCAmelCase  :  Any				       =[
              'safety_checker/pytorch_model.bin',
              'safety_checker/model.safetensors',
              'vae/diffusion_pytorch_model.bin',
              'vae/diffusion_pytorch_model.safetensors',
              'text_encoder/pytorch_model.bin',
              'text_encoder/model.safetensors',
              'unet/diffusion_pytorch_model.bin',
              'unet/diffusion_pytorch_model.safetensors',
          ]
          self.assertTrue(is_safetensors_compatible(snake_case))






       def      lowerCAmelCase						(     self)		->    List[str]:




          '''simple docstring'''
          _UpperCAmelCase  :  Optional[int]				       =[
              'unet/diffusion_pytorch_model.bin',
              'unet/diffusion_pytorch_model.safetensors',
          ]
          self.assertTrue(is_safetensors_compatible(snake_case))






       def      lowerCAmelCase						(     self)		->    Any:




          '''simple docstring'''
          _UpperCAmelCase  :  Union[str, Any]				       =[
              'safety_checker/pytorch_model.bin',
              'safety_checker/model.safetensors',
              'vae/diffusion_pytorch_model.bin',
              'vae/diffusion_pytorch_model.safetensors',
              'text_encoder/pytorch_model.bin',
              'text_encoder/model.safetensors',
              'unet/diffusion_pytorch_model.bin',
              # Removed: 'unet/diffusion_pytorch_model.safetensors',
          ]
          self.assertFalse(is_safetensors_compatible(snake_case))






       def      lowerCAmelCase						(     self)		->    Dict:




          '''simple docstring'''
          _UpperCAmelCase  :  int				       =[
              'text_encoder/pytorch_model.bin',
              'text_encoder/model.safetensors',
          ]
          self.assertTrue(is_safetensors_compatible(snake_case))






       def      lowerCAmelCase						(     self)		->    Any:




          '''simple docstring'''
          _UpperCAmelCase  :  Any				       =[
              'safety_checker/pytorch_model.bin',
              'safety_checker/model.safetensors',
              'vae/diffusion_pytorch_model.bin',
              'vae/diffusion_pytorch_model.safetensors',
              'text_encoder/pytorch_model.bin',
              # Removed: 'text_encoder/model.safetensors',
              'unet/diffusion_pytorch_model.bin',
              'unet/diffusion_pytorch_model.safetensors',
          ]
          self.assertFalse(is_safetensors_compatible(snake_case))






       def      lowerCAmelCase						(     self)		->    List[Any]:




          '''simple docstring'''
          _UpperCAmelCase  :  Union[str, Any]				       =[
              'safety_checker/pytorch_model.fp16.bin',
              'safety_checker/model.fp16.safetensors',
              'vae/diffusion_pytorch_model.fp16.bin',
              'vae/diffusion_pytorch_model.fp16.safetensors',
              'text_encoder/pytorch_model.fp16.bin',
              'text_encoder/model.fp16.safetensors',
              'unet/diffusion_pytorch_model.fp16.bin',
              'unet/diffusion_pytorch_model.fp16.safetensors',
          ]
          _UpperCAmelCase  :  str				       ='fp16'
          self.assertTrue(is_safetensors_compatible(snake_case    ,				variant=snake_case))






       def      lowerCAmelCase						(     self)		->    Union[str, Any]:




          '''simple docstring'''
          _UpperCAmelCase  :  Tuple				       =[
              'unet/diffusion_pytorch_model.fp16.bin',
              'unet/diffusion_pytorch_model.fp16.safetensors',
          ]
          _UpperCAmelCase  :  int				       ='fp16'
          self.assertTrue(is_safetensors_compatible(snake_case    ,				variant=snake_case))






       def      lowerCAmelCase						(     self)		->    Optional[int]:




          '''simple docstring'''
          # pass variant but use the non-variant filenames
          _UpperCAmelCase  :  Optional[int]				       =[
              'unet/diffusion_pytorch_model.bin',
              'unet/diffusion_pytorch_model.safetensors',
          ]
          _UpperCAmelCase  :  Optional[Any]				       ='fp16'
          self.assertTrue(is_safetensors_compatible(snake_case    ,				variant=snake_case))






       def      lowerCAmelCase						(     self)		->    int:




          '''simple docstring'''
          _UpperCAmelCase  :  str				       =[
              'safety_checker/pytorch_model.fp16.bin',
              'safety_checker/model.fp16.safetensors',
              'vae/diffusion_pytorch_model.fp16.bin',
              'vae/diffusion_pytorch_model.fp16.safetensors',
              'text_encoder/pytorch_model.fp16.bin',
              'text_encoder/model.fp16.safetensors',
              'unet/diffusion_pytorch_model.fp16.bin',
              # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
          ]
          _UpperCAmelCase  :  List[str]				       ='fp16'
          self.assertFalse(is_safetensors_compatible(snake_case    ,				variant=snake_case))






       def      lowerCAmelCase						(     self)		->    Union[str, Any]:




          '''simple docstring'''
          _UpperCAmelCase  :  Dict				       =[
              'text_encoder/pytorch_model.fp16.bin',
              'text_encoder/model.fp16.safetensors',
          ]
          _UpperCAmelCase  :  Optional[Any]				       ='fp16'
          self.assertTrue(is_safetensors_compatible(snake_case    ,				variant=snake_case))






       def      lowerCAmelCase						(     self)		->    Any:




          '''simple docstring'''
          # pass variant but use the non-variant filenames
          _UpperCAmelCase  :  Optional[int]				       =[
              'text_encoder/pytorch_model.bin',
              'text_encoder/model.safetensors',
          ]
          _UpperCAmelCase  :  List[Any]				       ='fp16'
          self.assertTrue(is_safetensors_compatible(snake_case    ,				variant=snake_case))






       def      lowerCAmelCase						(     self)		->    Union[str, Any]:




          '''simple docstring'''
          _UpperCAmelCase  :  str				       =[
              'safety_checker/pytorch_model.fp16.bin',
              'safety_checker/model.fp16.safetensors',
              'vae/diffusion_pytorch_model.fp16.bin',
              'vae/diffusion_pytorch_model.fp16.safetensors',
              'text_encoder/pytorch_model.fp16.bin',
              # 'text_encoder/model.fp16.safetensors',
              'unet/diffusion_pytorch_model.fp16.bin',
              'unet/diffusion_pytorch_model.fp16.safetensors',
          ]
          _UpperCAmelCase  :  Tuple				       ='fp16'
          self.assertFalse(is_safetensors_compatible(snake_case    ,				variant=snake_case))

