"""simple docstring"""



from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast
from ...utils import logging


__magic_name__     					=       logging.get_logger(__name__)

__magic_name__     					=       {
    "EleutherAI/gpt-neo-1.3B": "https://huggingface.co/EleutherAI/gpt-neo-1.3B/resolve/main/config.json",
    # See all GPTNeo models at https://huggingface.co/models?filter=gpt_neo
}

class SCREAMING_SNAKE_CASE  (     _SCREAMING_SNAKE_CASE						):







 """simple docstring"""


 a_							:						Tuple	      ="gpt_neo"
 a_							:						List[str]	      =["past_key_values"]
 a_							:						Tuple	      ={"num_attention_heads": "num_heads", "num_hidden_layers": "num_layers"}


 def __init__( self		:   Tuple       , _snake_case		:   Optional[int]=5_0257       , _snake_case		:   str=2048       , _snake_case		:   int=2048       , _snake_case		:   Any=24       , _snake_case		:   Tuple=[[["global", "local"], 12]]       , _snake_case		:   List[Any]=16       , _snake_case		:   Optional[int]=None       , _snake_case		:   Tuple=256       , _snake_case		:   int="gelu_new"       , _snake_case		:   int=0.0       , _snake_case		:   Union[str, Any]=0.0       , _snake_case		:   Dict=0.0       , _snake_case		:   int=0.1       , _snake_case		:   Any=1E-5       , _snake_case		:   str=0.02       , _snake_case		:   Any=True       , _snake_case		:   List[str]=5_0256       , _snake_case		:   Dict=5_0256       , **_snake_case		:   Any       , )					->      List[Any]:




    '''simple docstring'''






    a__  					=		vocab_size
    a__  					=		max_position_embeddings
    a__  					=		hidden_size
    a__  					=		num_layers
    a__  					=		num_heads
    a__  					=		intermediate_size
    a__  					=		window_size
    a__  					=		activation_function
    a__  					=		resid_dropout
    a__  					=		embed_dropout
    a__  					=		attention_dropout
    a__  					=		classifier_dropout
    a__  					=		layer_norm_epsilon
    a__  					=		initializer_range
    a__  					=		use_cache

    a__  					=		bos_token_id
    a__  					=		eos_token_id

    a__  					=		attention_types
    a__  					=		self.expand_attention_types_params(_snake_case					)

    if len(self.attention_layers					) != self.num_layers:
       raise ValueError(
           'Configuration for convolutional module is incorrect. '
           'It is required that `len(config.attention_layers)` == `config.num_layers` '
           F'''but is `len(config.attention_layers) = {len(self.attention_layers					)}`, '''
           F'''`config.num_layers = {self.num_layers}`. '''
           '`config.attention_layers` is prepared using `config.attention_types`. '
           'Please verify the value of `config.attention_types` argument.'					)

    super().__init__(bos_token_id=_snake_case       , eos_token_id=_snake_case       , **_snake_case					)



 @staticmethod
 def 							_lowerCAmelCase					( _snake_case		:   Any					)					->      List[str]:




    '''simple docstring'''






    a__  					=		[]
    for item in attention_types:
       for _ in range(item[1]					):
          attentions.extend(item[0]					)
    return attentions





def 	_lowerCamelCase			(			UpperCAmelCase__,UpperCAmelCase__,UpperCAmelCase__,UpperCAmelCase__       )				->  Optional[int]:


   '''simple docstring'''


   import torch

   a__  					=		input.size()
   a__  					=		len(A__       )
   a__  					=		shape[dimension]

   a__  					=		torch.arange(0,A__,A__       )
   a__  					=		torch.div(sizedim - size,A__,rounding_mode='floor'       ) + 1
   a__  					=		torch.arange(A__       ) + low_indices[:min_length][:, None]

   a__  					=		[slice(A__       )] * rank
   a__  					=		indices
   a__  					=		input[s]

   a__  					=		list(range(0,rank + 1       )       )
   perm.append(perm.pop(dimension + 1       )       )

   return sliced.permute(A__       )





def 	_lowerCamelCase			(			UpperCAmelCase__,UpperCAmelCase__       )				->  Dict:


   '''simple docstring'''


   import torch

   a__  					=		torch.arange(1,A__       )
   a__  					=		torch.remainder(A__,A__       )
   a__  					=		remainders == 0
   a__  					=		candidates[divisor_indices]
   a__  					=		torch.max(A__       )
   return largest_divisor, torch.div(A__,A__,rounding_mode='floor'       )




class SCREAMING_SNAKE_CASE  (     _SCREAMING_SNAKE_CASE						):







 """simple docstring"""


 @property
 def 							_lowerCAmelCase					( self		:   List[str]					)					->      Mapping[str, Mapping[int, str]]:




    '''simple docstring'''






    a__  					=		OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}					)
    if self.use_past:
       self.fill_with_past_key_values_(_snake_case       , direction='inputs'					)
       a__  					=		{0: """batch""", 1: """past_sequence + sequence"""}
    else:
       a__  					=		{0: """batch""", 1: """sequence"""}

    return common_inputs


 @property
 def 							_lowerCAmelCase					( self		:   Any					)					->      int:




    '''simple docstring'''






    return self._config.num_heads


 def 							_lowerCAmelCase					( self		:   Optional[int]       , _snake_case		:   PreTrainedTokenizer       , _snake_case		:   int = -1       , _snake_case		:   int = -1       , _snake_case		:   bool = False       , _snake_case		:   Optional[TensorType] = None       , )					->      Mapping[str, Any]:




    '''simple docstring'''






    a__  					=		super(_snake_case       , self					).generate_dummy_inputs(
        _snake_case       , batch_size=_snake_case       , seq_length=_snake_case       , is_pair=_snake_case       , framework=_snake_case					)

    # We need to order the input in the way they appears in the forward()
    a__  					=		OrderedDict({'input_ids': common_inputs['input_ids']}					)

    # Need to add the past_keys
    if self.use_past:
       if not is_torch_available():
          raise ValueError('Cannot generate dummy past_keys inputs without PyTorch installed.'					)
       else:
          import torch

          a__  					=		common_inputs["""input_ids"""].shape
          # Not using the same length for past_key_values
          a__  					=		seqlen + 2
          a__  					=		(
              batch,
              self.num_attention_heads,
              past_key_values_length,
              self._config.hidden_size // self.num_attention_heads,
          )
          a__  					=		[
              (torch.zeros(_snake_case					), torch.zeros(_snake_case					)) for _ in range(self.num_layers					)
          ]

    a__  					=		common_inputs["""attention_mask"""]
    if self.use_past:
       a__  					=		ordered_inputs["""attention_mask"""].dtype
       a__  					=		torch.cat(
           [ordered_inputs['attention_mask'], torch.ones(_snake_case       , _snake_case       , dtype=_snake_case					)]       , dim=1					)

    return ordered_inputs



 @property
 def 							_lowerCAmelCase					( self		:   Optional[int]					)					->      int:




    '''simple docstring'''






    return 13






'''simple docstring'''






from math import factorial

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







def 							UpperCamelCase_     (       A__   :  int   ):
  '''simple docstring'''





  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 							UpperCamelCase_     (       A__   :  int = 60				,       A__   :  int = 1_00_00_00   ):
  '''simple docstring'''





  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
  lowerCAmelCase_     : Optional[int]     =  0
  # the cached sizes of the previous chains
  lowerCAmelCase_     : dict[int, int]     =  {}

  for start_chain_element in range(1				,       A__   ):
    # The temporary set will contain the elements of the chain
    lowerCAmelCase_     : List[str]     =  set()
    lowerCAmelCase_     : Optional[int]     =  0

    # Stop computing the chain when you find a cached size, a repeating item or the
    # length is greater then the desired one.
    lowerCAmelCase_     : int     =  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
      lowerCAmelCase_     : Union[str, Any]     =  digit_factorial_sum(A__   )

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

    lowerCAmelCase_     : int     =  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()}''')



