



"""simple docstring"""




from math import factorial

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

def 						__snake_case						(				SCREAMING_SNAKE_CASE__     :						int    )  ->       int:





     '''simple docstring'''

     if not isinstance(SCREAMING_SNAKE_CASE__						,  SCREAMING_SNAKE_CASE__    ):
          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(SCREAMING_SNAKE_CASE__    )    )

def 						__snake_case						(				SCREAMING_SNAKE_CASE__     :						int = 60						,  SCREAMING_SNAKE_CASE__     :						int = 1_000_000    )  ->       int:





     '''simple docstring'''

     if not isinstance(SCREAMING_SNAKE_CASE__						,  SCREAMING_SNAKE_CASE__    ) or not isinstance(SCREAMING_SNAKE_CASE__						,  SCREAMING_SNAKE_CASE__    ):
          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
     _UpperCAmelCase      :     Any        =   0
     # the cached sizes of the previous chains
     _UpperCAmelCase      :     dict[int, int]        =   {}

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

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

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

          _UpperCAmelCase      :     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()}")





"""simple docstring"""




def 						__snake_case						(				SCREAMING_SNAKE_CASE__     :						list    )  ->       list:





     '''simple docstring'''

     if len(SCREAMING_SNAKE_CASE__    ) < 2:
          return collection

     def circle_sort_util(SCREAMING_SNAKE_CASE__     :						list						,  SCREAMING_SNAKE_CASE__     :						int						,  SCREAMING_SNAKE_CASE__     :						int    ) -> bool:
          _UpperCAmelCase      :     Dict        =   False

          if low == high:
               return swapped

          _UpperCAmelCase      :     str        =   low
          _UpperCAmelCase      :     Dict        =   high

          while left < right:
               if collection[left] > collection[right]:
                    _UpperCAmelCase    ,	_UpperCAmelCase      :     List[str]        =   (
                        collection[right],
                        collection[left],
                    )
                    _UpperCAmelCase      :     Optional[int]        =   True

               left += 1
               right -= 1

          if left == right and collection[left] > collection[right + 1]:
               _UpperCAmelCase    ,	_UpperCAmelCase      :     int        =   (
                   collection[right + 1],
                   collection[left],
               )

               _UpperCAmelCase      :     Union[str, Any]        =   True

          _UpperCAmelCase      :     Dict        =   low + int((high - low) / 2    )
          _UpperCAmelCase      :     Any        =   circle_sort_util(SCREAMING_SNAKE_CASE__						,  SCREAMING_SNAKE_CASE__						,  SCREAMING_SNAKE_CASE__    )
          _UpperCAmelCase      :     Optional[Any]        =   circle_sort_util(SCREAMING_SNAKE_CASE__						,  mid + 1						,  SCREAMING_SNAKE_CASE__    )

          return swapped or left_swap or right_swap

     _UpperCAmelCase      :     Tuple        =   True

     while is_not_sorted is True:
          _UpperCAmelCase      :     Dict        =   circle_sort_util(SCREAMING_SNAKE_CASE__						,  0						,  len(SCREAMING_SNAKE_CASE__    ) - 1    )

     return collection


if __name__ == "__main__":
 _lowerCAmelCase    : Dict							=							input("Enter numbers separated by a comma:\n").strip()
 _lowerCAmelCase    : Optional[Any]							=							[int(item) for item in user_input.split(",")]
 print(circle_sort(unsorted))
