





from typing import List, Optional, Union

import numpy as np
import PIL.Image

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


UpperCamelCase__   : Tuple					  = logging.get_logger(__name__)







class   _UpperCamelCase  (       A_  ):







					'''simple docstring'''

					lowerCamelCase     :     Optional[Any]			    =       ['pixel_values']





					def __init__(						self    :  str ,					__lowercase    :  bool = True ,					__lowercase    :  int = 32 ,					__lowercase    :  Tuple=PILImageResampling.BILINEAR ,					__lowercase    :  bool = True ,					**__lowercase    :  Dict ,					):






						'''simple docstring'''







						UpperCAmelCase_								=     do_resize
						UpperCAmelCase_								=     do_rescale
						UpperCAmelCase_								=     size_divisor
						UpperCAmelCase_								=     resample
						super().__init__(**__lowercase		)





					def        SCREAMING_SNAKE_CASE							(						self    :  str ,					__lowercase    :  np.ndarray ,					__lowercase    :  int ,					__lowercase    :  int ,					__lowercase    :  Optional[ChannelDimension] = None ,					**__lowercase    :  Optional[int]		):






						'''simple docstring'''







						UpperCAmelCase_						,	UpperCAmelCase_								=     get_image_size(__lowercase		)
						# Rounds the height and width down to the closest multiple of size_divisor
						UpperCAmelCase_								=     height // size_divisor * size_divisor
						UpperCAmelCase_								=     width // size_divisor * size_divisor
						UpperCAmelCase_								=     resize(__lowercase ,					(new_h, new_w) ,					resample=__lowercase ,					data_format=__lowercase ,					**__lowercase		)
						return image





					def        SCREAMING_SNAKE_CASE							(						self    :  Optional[Any] ,					__lowercase    :  np.ndarray ,					__lowercase    :  float ,					__lowercase    :  Optional[ChannelDimension] = None ,					**__lowercase    :  Dict		):






						'''simple docstring'''







						return rescale(image=__lowercase ,					scale=__lowercase ,					data_format=__lowercase ,					**__lowercase		)





					def        SCREAMING_SNAKE_CASE							(						self    :  Any ,					__lowercase    :  Union["PIL.Image.Image", TensorType, List["PIL.Image.Image"], List[TensorType]] ,					__lowercase    :  Optional[bool] = None ,					__lowercase    :  Optional[int] = None ,					__lowercase    :  List[Any]=None ,					__lowercase    :  Optional[bool] = None ,					__lowercase    :  Optional[Union[TensorType, str]] = None ,					__lowercase    :  ChannelDimension = ChannelDimension.FIRST ,					**__lowercase    :  Dict ,					):






						'''simple docstring'''







						UpperCAmelCase_								=     do_resize if do_resize is not None else self.do_resize
						UpperCAmelCase_								=     do_rescale if do_rescale is not None else self.do_rescale
						UpperCAmelCase_								=     size_divisor if size_divisor is not None else self.size_divisor
						UpperCAmelCase_								=     resample if resample is not None else self.resample

						if do_resize and size_divisor is None:
							raise ValueError("""size_divisor is required for resizing"""		)

						UpperCAmelCase_								=     make_list_of_images(__lowercase		)

						if not valid_images(__lowercase		):
							raise ValueError("""Invalid image(s)"""		)

						# All transformations expect numpy arrays.
						UpperCAmelCase_								=     [to_numpy_array(__lowercase		) for img in images]

						if do_resize:
							UpperCAmelCase_								=     [self.resize(__lowercase ,					size_divisor=__lowercase ,					resample=__lowercase		) for image in images]

						if do_rescale:
							UpperCAmelCase_								=     [self.rescale(__lowercase ,					scale=1 / 2_55		) for image in images]

						UpperCAmelCase_								=     [to_channel_dimension_format(__lowercase ,					__lowercase		) for image in images]

						UpperCAmelCase_								=     {"""pixel_values""": images}
						return BatchFeature(data=__lowercase ,					tensor_type=__lowercase		)









from math import factorial

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




def    A_(			A   ):
	if not isinstance(A				,      A   ):
		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(A   )   )




def    A_(			A = 60				,      A = 1000000   ):

	if not isinstance(A				,      A   ) or not isinstance(A				,      A   ):
		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
	UpperCAmelCase_								=     0
	# the cached sizes of the previous chains
	UpperCAmelCase_								=     {}

	for start_chain_element in range(1				,      A   ):
		# The temporary set will contain the elements of the chain
		UpperCAmelCase_								=     set()
		UpperCAmelCase_								=     0

		# Stop computing the chain when you find a cached size, a repeating item or the
		# length is greater then the desired one.
		UpperCAmelCase_								=     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(A   )
			chain_set_length += 1
			UpperCAmelCase_								=     digit_factorial_sum(A   )

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

		UpperCAmelCase_								=     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()}")


