



from math import factorial

lowercase_								=     {str(digit): factorial(digit) for digit in range(10)}



def __lowerCAmelCase (     SCREAMING_SNAKE_CASE_  ):
			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 __lowerCAmelCase (     SCREAMING_SNAKE_CASE_ = 60						,  SCREAMING_SNAKE_CASE_ = 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
			lowercase__					  =				0
			# the cached sizes of the previous chains
			lowercase__					  =				{}

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

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

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

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









import json
from typing import Iterator, List, Union

from tokenizers import AddedToken, Regex, Tokenizer, decoders, normalizers, pre_tokenizers, trainers
from tokenizers.implementations.base_tokenizer import BaseTokenizer
from tokenizers.models import Unigram
from tokenizers.processors import TemplateProcessing
class 				_snake_case			(					lowercase__):




				def __init__(						self					:						Optional[Any],					__lowercase					:						str = "▁",					__lowercase					:						bool = True,					__lowercase					:						Union[str, AddedToken] = "<unk>",					__lowercase					:						Union[str, AddedToken] = "</s>",					__lowercase					:						Union[str, AddedToken] = "<pad>",					):
							lowercase__					  =				{
							    "pad": {"id": 0, "token": pad_token},
							    "eos": {"id": 1, "token": eos_token},
							    "unk": {"id": 2, "token": unk_token},
							}

							lowercase__					  =				[None] * len(self.special_tokens						)
							for token_dict in self.special_tokens.values():
										lowercase__					  =				token_dict["token"]

							lowercase__					  =				Tokenizer(Unigram()						)

							lowercase__					  =				normalizers.Sequence(
							    [
							        normalizers.Nmt(),
							        normalizers.NFKC(),
							        normalizers.Replace(Regex(" {2,}"						),					" "						),
							        normalizers.Lowercase(),
							    ]						)
							lowercase__					  =				pre_tokenizers.Sequence(
							    [
							        pre_tokenizers.Metaspace(replacement=__lowercase,					add_prefix_space=__lowercase						),
							        pre_tokenizers.Digits(individual_digits=__lowercase						),
							        pre_tokenizers.Punctuation(),
							    ]						)
							lowercase__					  =				decoders.Metaspace(replacement=__lowercase,					add_prefix_space=__lowercase						)

							lowercase__					  =				TemplateProcessing(
							    single=F'''$A {self.special_tokens["eos"]["token"]}''',					special_tokens=[(self.special_tokens["eos"]["token"], self.special_tokens["eos"]["id"])],					)

							lowercase__					  =				{
							    "model": "SentencePieceUnigram",
							    "replacement": replacement,
							    "add_prefix_space": add_prefix_space,
							}

							super().__init__(__lowercase,					__lowercase						)




				def 							A__      (						self					:						Union[str, Any],					__lowercase					:						Union[str, List[str]],					__lowercase					:						int = 8000,					__lowercase					:						bool = True,					):
							lowercase__					  =				trainers.UnigramTrainer(
							    vocab_size=__lowercase,					special_tokens=self.special_tokens_list,					show_progress=__lowercase,					)

							if isinstance(__lowercase,					__lowercase						):
										lowercase__					  =				[files]
							self._tokenizer.train(__lowercase,					trainer=__lowercase						)

							self.add_unk_id()




				def 							A__      (						self					:						List[Any],					__lowercase					:						Union[Iterator[str], Iterator[Iterator[str]]],					__lowercase					:						int = 8000,					__lowercase					:						bool = True,					):
							lowercase__					  =				trainers.UnigramTrainer(
							    vocab_size=__lowercase,					special_tokens=self.special_tokens_list,					show_progress=__lowercase,					)

							self._tokenizer.train_from_iterator(__lowercase,					trainer=__lowercase						)

							self.add_unk_id()




				def 							A__      (						self					:						str						):
							lowercase__					  =				json.loads(self._tokenizer.to_str()						)

							lowercase__					  =				self.special_tokens["unk"]["id"]

							lowercase__					  =				Tokenizer.from_str(json.dumps(__lowercase						)						)




