





import inspect
import re
from hashlib import shaaaa
from typing import Dict, List

from .arrow import arrow
from .audiofolder import audiofolder
from .csv import csv
from .imagefolder import imagefolder
from .json import json
from .pandas import pandas
from .parquet import parquet
from .sql import sql  # noqa F401
from .text import text







def    A				(							UpperCAmelCase				):
					_snake_case       :					Any				       =   []
					for line in lines:
										_snake_case       :					List[Any]				       =   re.sub(R"#.*"  ,  ""  ,  UpperCAmelCase				)  # remove comments
										if line:
															filtered_lines.append(UpperCAmelCase				)
					_snake_case       :					Dict				       =   "\n".join(UpperCAmelCase				)

					# Make a hash from all this code
					_snake_case       :					Optional[int]				       =   full_str.encode("utf-8"				)
					return shaaaa(UpperCAmelCase				).hexdigest()


# get importable module names and hash for caching
__lowerCAmelCase :Any     =    {
    'csv': (csv.__name__, _hash_python_lines(inspect.getsource(csv).splitlines())),
    'json': (json.__name__, _hash_python_lines(inspect.getsource(json).splitlines())),
    'pandas': (pandas.__name__, _hash_python_lines(inspect.getsource(pandas).splitlines())),
    'parquet': (parquet.__name__, _hash_python_lines(inspect.getsource(parquet).splitlines())),
    'arrow': (arrow.__name__, _hash_python_lines(inspect.getsource(arrow).splitlines())),
    'text': (text.__name__, _hash_python_lines(inspect.getsource(text).splitlines())),
    'imagefolder': (imagefolder.__name__, _hash_python_lines(inspect.getsource(imagefolder).splitlines())),
    'audiofolder': (audiofolder.__name__, _hash_python_lines(inspect.getsource(audiofolder).splitlines())),
}

# Used to infer the module to use based on the data files extensions
__lowerCAmelCase :int     =    {
    '.csv': ('csv', {}),
    '.tsv': ('csv', {'sep': '\t'}),
    '.json': ('json', {}),
    '.jsonl': ('json', {}),
    '.parquet': ('parquet', {}),
    '.arrow': ('arrow', {}),
    '.txt': ('text', {}),
}
_EXTENSION_TO_MODULE.update({ext: ('imagefolder', {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ('imagefolder', {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext: ('audiofolder', {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ('audiofolder', {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
__lowerCAmelCase :List[str]     =    {'imagefolder', 'audiofolder'}

# Used to filter data files based on extensions given a module name
__lowerCAmelCase :Dict[str, List[str]]     =    {}
for _ext, (_module, _) in _EXTENSION_TO_MODULE.items():
			_MODULE_TO_EXTENSIONS.setdefault(_module, []).append(_ext)

_MODULE_TO_EXTENSIONS["imagefolder"].append('.zip')

_MODULE_TO_EXTENSIONS["audiofolder"].append('.zip')






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