





from math import factorial

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





def 					lowerCAmelCase_			(	__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 					lowerCAmelCase_			(	__a = 60     ,   __a = 1000000		)					->		int:







  """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__:				Any        =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__:				int        =set()
    lowerCamelCase__:				Optional[Any]        =0

    # Stop computing the chain when you find a cached size, a repeating item or the
    # length is greater then the desired one.
    lowerCamelCase__:				Optional[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__:				List[str]        =digit_factorial_sum(__a		)

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

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








import argparse
import logging
import pickle
from collections import Counter


logging.basicConfig(
    format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%m/%d/%Y %H:%M:%S", level=logging.INFO
)
__A     =    logging.getLogger(__name__)

if __name__ == "__main__":
     __A     =    argparse.ArgumentParser(
         description="Token Counts for smoothing the masking probabilities in MLM (cf XLM/word2vec)"
     )
     parser.add_argument(
         "--data_file", type=str, default="data/dump.bert-base-uncased.pickle", help="The binarized dataset."
     )
     parser.add_argument(
         "--token_counts_dump", type=str, default="data/token_counts.bert-base-uncased.pickle", help="The dump file."
     )
     parser.add_argument("--vocab_size", default=3_0522, type=int)
     __A     =    parser.parse_args()

     logger.info(f'Loading data from {args.data_file}')
     with open(args.data_file, "rb") as fp:
          __A     =    pickle.load(fp)

     logger.info("Counting occurrences for MLM.")
     __A     =    Counter()
     for tk_ids in data:
          counter.update(tk_ids)
     __A     =    [0] * args.vocab_size
     for k, v in counter.items():
          __A     =    v

     logger.info(f'Dump to {args.token_counts_dump}')
     with open(args.token_counts_dump, "wb") as handle:
          pickle.dump(counts, handle, protocol=pickle.HIGHEST_PROTOCOL)

