






'''simple docstring'''







import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
							pass

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase    :      str  			=		logging.get_logger(__name__)

UpperCamelCase    :      List[str]  			=		{
    'kakaobrain/align-base': 'https://huggingface.co/kakaobrain/align-base/resolve/main/config.json',
}




class 		UpperCamelCase__    (a			):




		'''simple docstring'''





		_UpperCamelCase				  =					'align_text_model'






		def __init__(      self   ,_lowerCAmelCase=3_05_22   ,_lowerCAmelCase=7_68   ,_lowerCAmelCase=12   ,_lowerCAmelCase=12   ,_lowerCAmelCase=30_72   ,_lowerCAmelCase="gelu"   ,_lowerCAmelCase=0.1   ,_lowerCAmelCase=0.1   ,_lowerCAmelCase=5_12   ,_lowerCAmelCase=2   ,_lowerCAmelCase=0.02   ,_lowerCAmelCase=1E-12   ,_lowerCAmelCase=0   ,_lowerCAmelCase="absolute"   ,_lowerCAmelCase=True   ,**_lowerCAmelCase   ,):
								super().__init__(**_lowerCAmelCase       )

								lowerCamelCase__         =  vocab_size
								lowerCamelCase__         =  hidden_size
								lowerCamelCase__         =  num_hidden_layers
								lowerCamelCase__         =  num_attention_heads
								lowerCamelCase__         =  hidden_act
								lowerCamelCase__         =  intermediate_size
								lowerCamelCase__         =  hidden_dropout_prob
								lowerCamelCase__         =  attention_probs_dropout_prob
								lowerCamelCase__         =  max_position_embeddings
								lowerCamelCase__         =  type_vocab_size
								lowerCamelCase__         =  initializer_range
								lowerCamelCase__         =  layer_norm_eps
								lowerCamelCase__         =  position_embedding_type
								lowerCamelCase__         =  use_cache
								lowerCamelCase__         =  pad_token_id






		@classmethod
		def 			UpperCamelCase_					(      cls   ,_lowerCAmelCase   ,**_lowerCAmelCase       ):
								cls._set_token_in_kwargs(_lowerCAmelCase       )

								lowerCamelCase__       ,			lowerCamelCase__         =  cls.get_config_dict(_lowerCAmelCase   ,**_lowerCAmelCase       )

								# get the text config dict if we are loading from AlignConfig
								if config_dict.get("""model_type"""       ) == "align":
														lowerCamelCase__         =  config_dict["""text_config"""]

								if "model_type" in config_dict and hasattr(cls   ,"""model_type"""       ) and config_dict["model_type"] != cls.model_type:
														logger.warning(
														    F'''You are using a model of type {config_dict["model_type"]} to instantiate a model of type '''
														    F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''       )

								return cls.from_dict(_lowerCAmelCase   ,**_lowerCAmelCase       )




class 		UpperCamelCase__    (a			):




		'''simple docstring'''





		_UpperCamelCase				  =					'align_vision_model'






		def __init__(      self   ,_lowerCAmelCase = 3   ,_lowerCAmelCase = 6_00   ,_lowerCAmelCase = 2.0   ,_lowerCAmelCase = 3.1   ,_lowerCAmelCase = 8   ,_lowerCAmelCase = [3, 3, 5, 3, 5, 5, 3]   ,_lowerCAmelCase = [32, 16, 24, 40, 80, 1_12, 1_92]   ,_lowerCAmelCase = [16, 24, 40, 80, 1_12, 1_92, 3_20]   ,_lowerCAmelCase = []   ,_lowerCAmelCase = [1, 2, 2, 2, 1, 2, 1]   ,_lowerCAmelCase = [1, 2, 2, 3, 3, 4, 1]   ,_lowerCAmelCase = [1, 6, 6, 6, 6, 6, 6]   ,_lowerCAmelCase = 0.25   ,_lowerCAmelCase = "swish"   ,_lowerCAmelCase = 25_60   ,_lowerCAmelCase = "mean"   ,_lowerCAmelCase = 0.02   ,_lowerCAmelCase = 0.001   ,_lowerCAmelCase = 0.99   ,_lowerCAmelCase = 0.2   ,**_lowerCAmelCase   ,):
								super().__init__(**_lowerCAmelCase       )

								lowerCamelCase__         =  num_channels
								lowerCamelCase__         =  image_size
								lowerCamelCase__         =  width_coefficient
								lowerCamelCase__         =  depth_coefficient
								lowerCamelCase__         =  depth_divisor
								lowerCamelCase__         =  kernel_sizes
								lowerCamelCase__         =  in_channels
								lowerCamelCase__         =  out_channels
								lowerCamelCase__         =  depthwise_padding
								lowerCamelCase__         =  strides
								lowerCamelCase__         =  num_block_repeats
								lowerCamelCase__         =  expand_ratios
								lowerCamelCase__         =  squeeze_expansion_ratio
								lowerCamelCase__         =  hidden_act
								lowerCamelCase__         =  hidden_dim
								lowerCamelCase__         =  pooling_type
								lowerCamelCase__         =  initializer_range
								lowerCamelCase__         =  batch_norm_eps
								lowerCamelCase__         =  batch_norm_momentum
								lowerCamelCase__         =  drop_connect_rate
								lowerCamelCase__         =  sum(_lowerCAmelCase       ) * 4






		@classmethod
		def 			UpperCamelCase_					(      cls   ,_lowerCAmelCase   ,**_lowerCAmelCase       ):
								cls._set_token_in_kwargs(_lowerCAmelCase       )

								lowerCamelCase__       ,			lowerCamelCase__         =  cls.get_config_dict(_lowerCAmelCase   ,**_lowerCAmelCase       )

								# get the vision config dict if we are loading from AlignConfig
								if config_dict.get("""model_type"""       ) == "align":
														lowerCamelCase__         =  config_dict["""vision_config"""]

								if "model_type" in config_dict and hasattr(cls   ,"""model_type"""       ) and config_dict["model_type"] != cls.model_type:
														logger.warning(
														    F'''You are using a model of type {config_dict["model_type"]} to instantiate a model of type '''
														    F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''       )

								return cls.from_dict(_lowerCAmelCase   ,**_lowerCAmelCase       )




class 		UpperCamelCase__    (a			):




		'''simple docstring'''





		_UpperCamelCase				  =					'align'
		_UpperCamelCase				  =					True






		def __init__(      self   ,_lowerCAmelCase=None   ,_lowerCAmelCase=None   ,_lowerCAmelCase=6_40   ,_lowerCAmelCase=1.0   ,_lowerCAmelCase=0.02   ,**_lowerCAmelCase   ,):
								super().__init__(**_lowerCAmelCase       )

								if text_config is None:
														lowerCamelCase__         =  {}
														logger.info("""text_config is None. Initializing the AlignTextConfig with default values."""       )

								if vision_config is None:
														lowerCamelCase__         =  {}
														logger.info("""vision_config is None. Initializing the AlignVisionConfig with default values."""       )

								lowerCamelCase__         =  AlignTextConfig(**_lowerCAmelCase       )
								lowerCamelCase__         =  AlignVisionConfig(**_lowerCAmelCase       )

								lowerCamelCase__         =  projection_dim
								lowerCamelCase__         =  temperature_init_value
								lowerCamelCase__         =  initializer_range






		@classmethod
		def 			UpperCamelCase_					(      cls   ,_lowerCAmelCase   ,_lowerCAmelCase   ,**_lowerCAmelCase       ):
								return cls(text_config=text_config.to_dict()   ,vision_config=vision_config.to_dict()   ,**_lowerCAmelCase       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  copy.deepcopy(self.__dict__       )
								lowerCamelCase__         =  self.text_config.to_dict()
								lowerCamelCase__         =  self.vision_config.to_dict()
								lowerCamelCase__         =  self.__class__.model_type
								return output









'''simple docstring'''







from math import factorial

UpperCamelCase    :      dict[str, int]  			=		{str(digit): factorial(digit) for digit in range(10)}
def 						A__			(				__lowerCAmelCase		:			int						):
						if not isinstance(__lowerCAmelCase   ,    __lowerCAmelCase						):
												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(__lowerCAmelCase						)						)
def 						A__			(				__lowerCAmelCase		:			int = 60   ,    __lowerCAmelCase		:			int = 100_0000						):

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

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

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

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

												lowerCamelCase__         =  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()}')

