


'''simple docstring'''



from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


_lowercase      :      List[str]            =					logging.get_logger(__name__)


if is_vision_available():
	import PIL






class 	UpperCamelCase__(       lowerCAmelCase	):
				__magic_name__    :				Any  		=	["pixel_values"]




				def __init__(		self      :			List[str]				,   lowerCAmelCase      :			bool = True				,   lowerCAmelCase      :			Dict[str, int] = None				,   lowerCAmelCase      :			PILImageResampling = PILImageResampling.BICUBIC				,   lowerCAmelCase      :			bool = True				,   lowerCAmelCase      :			Dict[str, int] = None				,   lowerCAmelCase      :			bool = True				,   lowerCAmelCase      :			Union[int, float] = 1 / 255				,   lowerCAmelCase      :			bool = True				,   lowerCAmelCase      :			Optional[Union[float, List[float]]] = None				,   lowerCAmelCase      :			Optional[Union[float, List[float]]] = None				,   lowerCAmelCase      :			bool = True				,   **lowerCAmelCase      :			List[Any]				,   )->					None:

										"""simple docstring"""




										super().__init__(**lowerCAmelCase				)
										UpperCAmelCase					    =     size if size is not None else {'''shortest_edge''': 224}
										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				,   default_to_square=lowerCAmelCase				)
										UpperCAmelCase					    =     crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				,   default_to_square=lowerCAmelCase				,   param_name='''crop_size'''				)

										UpperCAmelCase					    =     do_resize
										UpperCAmelCase					    =     size
										UpperCAmelCase					    =     resample
										UpperCAmelCase					    =     do_center_crop
										UpperCAmelCase					    =     crop_size
										UpperCAmelCase					    =     do_rescale
										UpperCAmelCase					    =     rescale_factor
										UpperCAmelCase					    =     do_normalize
										UpperCAmelCase					    =     image_mean if image_mean is not None else OPENAI_CLIP_MEAN
										UpperCAmelCase					    =     image_std if image_std is not None else OPENAI_CLIP_STD
										UpperCAmelCase					    =     do_convert_rgb




				def 					a__(		self      :			List[Any]				,   lowerCAmelCase      :			np.ndarray				,   lowerCAmelCase      :			Dict[str, int]				,   lowerCAmelCase      :			PILImageResampling = PILImageResampling.BICUBIC				,   lowerCAmelCase      :			Optional[Union[str, ChannelDimension]] = None				,   **lowerCAmelCase      :			Optional[int]				,   )->					np.ndarray:

										"""simple docstring"""




										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				,   default_to_square=lowerCAmelCase				)
										if "shortest_edge" not in size:
																raise ValueError(F"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""				)
										UpperCAmelCase					    =     get_resize_output_image_size(lowerCAmelCase				,   size=size['''shortest_edge''']				,   default_to_square=lowerCAmelCase				)
										return resize(lowerCAmelCase				,   size=lowerCAmelCase				,   resample=lowerCAmelCase				,   data_format=lowerCAmelCase				,   **lowerCAmelCase				)




				def 					a__(		self      :			List[Any]				,   lowerCAmelCase      :			np.ndarray				,   lowerCAmelCase      :			Dict[str, int]				,   lowerCAmelCase      :			Optional[Union[str, ChannelDimension]] = None				,   **lowerCAmelCase      :			Union[str, Any]				,   )->					np.ndarray:

										"""simple docstring"""




										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				)
										if "height" not in size or "width" not in size:
																raise ValueError(F"""The `size` parameter must contain the keys (height, width). Got {size.keys()}"""				)
										return center_crop(lowerCAmelCase				,   size=(size['''height'''], size['''width'''])				,   data_format=lowerCAmelCase				,   **lowerCAmelCase				)




				def 					a__(		self      :			Any				,   lowerCAmelCase      :			np.ndarray				,   lowerCAmelCase      :			Union[int, float]				,   lowerCAmelCase      :			Optional[Union[str, ChannelDimension]] = None				,   **lowerCAmelCase      :			Union[str, Any]				,   )->					Tuple:

										"""simple docstring"""




										return rescale(lowerCAmelCase				,   scale=lowerCAmelCase				,   data_format=lowerCAmelCase				,   **lowerCAmelCase				)




				def 					a__(		self      :			Optional[Any]				,   lowerCAmelCase      :			np.ndarray				,   lowerCAmelCase      :			Union[float, List[float]]				,   lowerCAmelCase      :			Union[float, List[float]]				,   lowerCAmelCase      :			Optional[Union[str, ChannelDimension]] = None				,   **lowerCAmelCase      :			Optional[Any]				,   )->					np.ndarray:

										"""simple docstring"""




										return normalize(lowerCAmelCase				,   mean=lowerCAmelCase				,   std=lowerCAmelCase				,   data_format=lowerCAmelCase				,   **lowerCAmelCase				)





				def 					a__(		self      :			List[str]				,   lowerCAmelCase      :			ImageInput				,   lowerCAmelCase      :			bool = None				,   lowerCAmelCase      :			Dict[str, int] = None				,   lowerCAmelCase      :			PILImageResampling = None				,   lowerCAmelCase      :			bool = None				,   lowerCAmelCase      :			int = None				,   lowerCAmelCase      :			bool = None				,   lowerCAmelCase      :			float = None				,   lowerCAmelCase      :			bool = None				,   lowerCAmelCase      :			Optional[Union[float, List[float]]] = None				,   lowerCAmelCase      :			Optional[Union[float, List[float]]] = None				,   lowerCAmelCase      :			bool = None				,   lowerCAmelCase      :			Optional[Union[str, TensorType]] = None				,   lowerCAmelCase      :			Optional[ChannelDimension] = ChannelDimension.FIRST				,   **lowerCAmelCase      :			int				,   )->					PIL.Image.Image:

										"""simple docstring"""




										UpperCAmelCase					    =     do_resize if do_resize is not None else self.do_resize
										UpperCAmelCase					    =     size if size is not None else self.size
										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				,   param_name='''size'''				,   default_to_square=lowerCAmelCase				)
										UpperCAmelCase					    =     resample if resample is not None else self.resample
										UpperCAmelCase					    =     do_center_crop if do_center_crop is not None else self.do_center_crop
										UpperCAmelCase					    =     crop_size if crop_size is not None else self.crop_size
										UpperCAmelCase					    =     get_size_dict(lowerCAmelCase				,   param_name='''crop_size'''				,   default_to_square=lowerCAmelCase				)
										UpperCAmelCase					    =     do_rescale if do_rescale is not None else self.do_rescale
										UpperCAmelCase					    =     rescale_factor if rescale_factor is not None else self.rescale_factor
										UpperCAmelCase					    =     do_normalize if do_normalize is not None else self.do_normalize
										UpperCAmelCase					    =     image_mean if image_mean is not None else self.image_mean
										UpperCAmelCase					    =     image_std if image_std is not None else self.image_std
										UpperCAmelCase					    =     do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

										UpperCAmelCase					    =     make_list_of_images(lowerCAmelCase				)

										if not valid_images(lowerCAmelCase				):
																raise ValueError(
																    '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
																    '''torch.Tensor, tf.Tensor or jax.ndarray.'''				)

										if do_resize and size is None:
																raise ValueError('''Size must be specified if do_resize is True.'''				)

										if do_center_crop and crop_size is None:
																raise ValueError('''Crop size must be specified if do_center_crop is True.'''				)

										if do_rescale and rescale_factor is None:
																raise ValueError('''Rescale factor must be specified if do_rescale is True.'''				)

										if do_normalize and (image_mean is None or image_std is None):
																raise ValueError('''Image mean and std must be specified if do_normalize is True.'''				)

										# PIL RGBA images are converted to RGB
										if do_convert_rgb:
																UpperCAmelCase					    =     [convert_to_rgb(lowerCAmelCase				) for image in images]

										# All transformations expect numpy arrays.
										UpperCAmelCase					    =     [to_numpy_array(lowerCAmelCase				) for image in images]

										if do_resize:
																UpperCAmelCase					    =     [self.resize(image=lowerCAmelCase				,   size=lowerCAmelCase				,   resample=lowerCAmelCase				) for image in images]

										if do_center_crop:
																UpperCAmelCase					    =     [self.center_crop(image=lowerCAmelCase				,   size=lowerCAmelCase				) for image in images]

										if do_rescale:
																UpperCAmelCase					    =     [self.rescale(image=lowerCAmelCase				,   scale=lowerCAmelCase				) for image in images]

										if do_normalize:
																UpperCAmelCase					    =     [self.normalize(image=lowerCAmelCase				,   mean=lowerCAmelCase				,   std=lowerCAmelCase				) for image in images]

										UpperCAmelCase					    =     [to_channel_dimension_format(lowerCAmelCase				,   lowerCAmelCase				) for image in images]

										UpperCAmelCase					    =     {'''pixel_values''': images}
										return BatchFeature(data=lowerCAmelCase				,   tensor_type=lowerCAmelCase				)









'''simple docstring'''



_lowercase      :      Any            =					range(2, 20 + 1)
_lowercase      :      str            =					[10**k for k in range(ks[-1] + 1)]
_lowercase      :      dict[int, dict[int, list[list[int]]]]            =					{}


def 				lowerCamelCase__				(	A       :      int				,       A       :      str				,       A       :      List[Any]				,       A       :      Union[str, Any]					):




						'''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 				lowerCamelCase__				(	A       :      Dict				,       A       :      Optional[int]				,       A       :      List[Any]				,       A       :      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 				lowerCamelCase__				(	A       :      List[str]				,       A       :      Optional[int]				,       A       :      Optional[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 				lowerCamelCase__				(	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() = }""")





