





from typing import Dict, Iterable, List, Optional, Union

import numpy as np

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


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






class        _a(    _UpperCAmelCase    ):
		lowerCamelCase__     :Union[str, Any]   				=		['pixel_values']







		def __init__(    self ,						__snake_case = True ,						__snake_case = None ,						__snake_case = PILImageResampling.BICUBIC ,						__snake_case = True ,						__snake_case = None ,						__snake_case = True ,						__snake_case = 1 / 2_5_5 ,						__snake_case = True ,						__snake_case = IMAGENET_DEFAULT_MEAN ,						__snake_case = IMAGENET_DEFAULT_STD ,						**__snake_case ,						)      ->      None:


							'''simple docstring'''

							super().__init__(**lowerCamelCase_				)
							_snake_case       :					str				       =   size if size is not None else {'''shortest_edge''': 2_2_4}
							_snake_case       :					Optional[int]				       =   get_size_dict(lowerCamelCase_ ,						default_to_square=lowerCamelCase_				)
							_snake_case       :					Union[str, Any]				       =   crop_size if crop_size is not None else {'''height''': 2_2_4, '''width''': 2_2_4}
							_snake_case       :					Dict				       =   get_size_dict(lowerCamelCase_ ,						param_name="crop_size"				)

							_snake_case       :					List[str]				       =   do_resize
							_snake_case       :					Tuple				       =   size
							_snake_case       :					Optional[Any]				       =   resample
							_snake_case       :					Any				       =   do_center_crop
							_snake_case       :					List[str]				       =   crop_size
							_snake_case       :					int				       =   do_rescale
							_snake_case       :					Any				       =   rescale_factor
							_snake_case       :					str				       =   do_normalize
							_snake_case       :					List[str]				       =   image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
							_snake_case       :					Optional[Any]				       =   image_std if image_std is not None else IMAGENET_DEFAULT_STD







		def        lowercase       (    self ,						__snake_case ,						__snake_case ,						__snake_case = PILImageResampling.BICUBIC ,						__snake_case = None ,						**__snake_case ,						)      ->      np.ndarray:


							'''simple docstring'''

							_snake_case       :					List[Any]				       =   get_size_dict(lowerCamelCase_ ,						default_to_square=lowerCamelCase_				)
							# size_dict is a dict with either keys "height" and "width" or "shortest_edge"
							if "shortest_edge" in size:
												_snake_case       :					str				       =   int((2_5_6 / 2_2_4) * size["shortest_edge"]				)
												_snake_case       :					Any				       =   get_resize_output_image_size(lowerCamelCase_ ,						size=lowerCamelCase_ ,						default_to_square=lowerCamelCase_				)
												_snake_case       :					Optional[int]				       =   {'''height''': output_size[0], '''width''': output_size[1]}
							if "height" not in size_dict or "width" not in size_dict:
												raise ValueError(
												    f"""Size dict must have keys 'height' and 'width' or 'shortest_edge'. Got {size_dict.keys()}"""				)
							return resize(
							    lowerCamelCase_ ,						size=(size_dict["height"], size_dict["width"]) ,						resample=lowerCamelCase_ ,						data_format=lowerCamelCase_ ,						**lowerCamelCase_				)







		def        lowercase       (    self ,						__snake_case ,						__snake_case ,						__snake_case = None ,						**__snake_case ,						)      ->      np.ndarray:


							'''simple docstring'''

							_snake_case       :					Union[str, Any]				       =   get_size_dict(lowerCamelCase_				)
							if "height" not in size or "width" not in size:
												raise ValueError(f"""Size dict must have keys 'height' and 'width'. Got {size.keys()}"""				)
							return center_crop(lowerCamelCase_ ,						size=(size["height"], size["width"]) ,						data_format=lowerCamelCase_ ,						**lowerCamelCase_				)







		def        lowercase       (    self ,						__snake_case ,						__snake_case ,						__snake_case = None ,						**__snake_case ,						)      ->      np.ndarray:


							'''simple docstring'''

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







		def        lowercase       (    self ,						__snake_case ,						__snake_case ,						__snake_case ,						__snake_case = None ,						**__snake_case ,						)      ->      np.ndarray:


							'''simple docstring'''

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







		def        lowercase       (    self ,						__snake_case ,						__snake_case = None ,						__snake_case = None ,						__snake_case = None ,						__snake_case = None ,						__snake_case = None ,						__snake_case = None ,						__snake_case = None ,						__snake_case = None ,						__snake_case = None ,						__snake_case = None ,						__snake_case = None ,						__snake_case = ChannelDimension.FIRST ,						**__snake_case ,						)      ->      BatchFeature:


							'''simple docstring'''

							_snake_case       :					Optional[Any]				       =   do_resize if do_resize is not None else self.do_resize
							_snake_case       :					Optional[Any]				       =   resample if resample is not None else self.resample
							_snake_case       :					List[Any]				       =   do_center_crop if do_center_crop is not None else self.do_center_crop
							_snake_case       :					Dict				       =   do_rescale if do_rescale is not None else self.do_rescale
							_snake_case       :					Optional[int]				       =   rescale_factor if rescale_factor is not None else self.rescale_factor
							_snake_case       :					Optional[int]				       =   do_normalize if do_normalize is not None else self.do_normalize
							_snake_case       :					Dict				       =   image_mean if image_mean is not None else self.image_mean
							_snake_case       :					List[str]				       =   image_std if image_std is not None else self.image_std

							_snake_case       :					Union[str, Any]				       =   size if size is not None else self.size
							_snake_case       :					Union[str, Any]				       =   get_size_dict(lowerCamelCase_ ,						default_to_square=lowerCamelCase_				)
							_snake_case       :					str				       =   crop_size if crop_size is not None else self.crop_size
							_snake_case       :					List[Any]				       =   get_size_dict(lowerCamelCase_ ,						param_name="crop_size"				)

							_snake_case       :					str				       =   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."				)

							# All transformations expect numpy arrays.
							_snake_case       :					List[Any]				       =   [to_numpy_array(lowerCamelCase_				) for image in images]

							if do_resize:
												_snake_case       :					Union[str, Any]				       =   [self.resize(lowerCamelCase_ ,						lowerCamelCase_ ,						lowerCamelCase_				) for image in images]

							if do_center_crop:
												_snake_case       :					Union[str, Any]				       =   [self.center_crop(lowerCamelCase_ ,						lowerCamelCase_				) for image in images]

							if do_rescale:
												_snake_case       :					Tuple				       =   [self.rescale(lowerCamelCase_ ,						lowerCamelCase_				) for image in images]

							if do_normalize:
												_snake_case       :					Dict				       =   [self.normalize(lowerCamelCase_ ,						lowerCamelCase_ ,						lowerCamelCase_				) for image in images]

							_snake_case       :					List[str]				       =   [to_channel_dimension_format(lowerCamelCase_ ,						lowerCamelCase_				) for image in images]

							_snake_case       :					Any				       =   {'''pixel_values''': images}
							return BatchFeature(data=lowerCamelCase_ ,						tensor_type=lowerCamelCase_				)






from math import factorial

__lowerCAmelCase :dict[str, int]     =    {str(digit): factorial(digit) for digit in range(10)}







def    A				(							UpperCAmelCase				):
					if not isinstance(UpperCAmelCase  ,  UpperCAmelCase				):
										raise TypeError("Parameter number must be int"				)

					if number < 0:
										raise ValueError("Parameter number must be greater than or equal to 0"				)

					# Converts number in string to iterate on its digits and adds its factorial.
					return sum(DIGIT_FACTORIAL[digit] for digit in str(UpperCAmelCase				)				)







def    A				(							UpperCAmelCase = 60  ,  UpperCAmelCase = 1_000_000				):

					if not isinstance(UpperCAmelCase  ,  UpperCAmelCase				) or not isinstance(UpperCAmelCase  ,  UpperCAmelCase				):
										raise TypeError("Parameters chain_length and number_limit must be int"				)

					if chain_length <= 0 or number_limit <= 0:
										raise ValueError(
										    "Parameters chain_length and number_limit must be greater than 0"				)

					# the counter for the chains with the exact desired length
					_snake_case       :					Optional[int]				       =   0
					# the cached sizes of the previous chains
					_snake_case       :					dict[int, int]				       =   {}

					for start_chain_element in range(1  ,  UpperCAmelCase				):
										# The temporary set will contain the elements of the chain
										_snake_case       :					Union[str, Any]				       =   set()
										_snake_case       :					Tuple				       =   0

										# Stop computing the chain when you find a cached size, a repeating item or the
										# length is greater then the desired one.
										_snake_case       :					str				       =   start_chain_element
										while (
										    chain_element not in chain_sets_lengths
										    and chain_element not in chain_set
										    and chain_set_length <= chain_length
										):
															chain_set.add(UpperCAmelCase				)
															chain_set_length += 1
															_snake_case       :					Optional[Any]				       =   digit_factorial_sum(UpperCAmelCase				)

										if chain_element in chain_sets_lengths:
															chain_set_length += chain_sets_lengths[chain_element]

										_snake_case       :					List[Any]				       =   chain_set_length

										# If chain contains the exact amount of elements increase the counter
										if chain_set_length == chain_length:
															chains_counter += 1

					return chains_counter


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							print(F'''{solution()}''')