from math import factorial

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



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	int     )							-> str:







    """simple docstring"""





    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      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	List[str] = 60			,					__UpperCamelCase   :	Optional[int] = 1_00_00_00     )							-> str:







    """simple docstring"""





    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
    SCREAMING_SNAKE_CASE__      							=				0
    # the cached sizes of the previous chains
    SCREAMING_SNAKE_CASE__      							=				{}

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

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

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

        SCREAMING_SNAKE_CASE__      							=				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()}""")

from __future__ import annotations

__lowerCamelCase      :			Dict							       =		[-10, -5, 0, 5, 5.1, 11, 13, 21, 3, 4, -21, -10, -5, -1, 0]
__lowerCamelCase      :			Union[str, Any]							       =		[-5, 0, 5, 5.1, 11, 13, 21, -1, 4, -1, -10, -5, -1, 0, -1]



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	list[float]     )							-> list[float]:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__      							=				[]
  SCREAMING_SNAKE_CASE__      							=				len(__UpperCamelCase     )

  for i in range(__UpperCamelCase     ):
    SCREAMING_SNAKE_CASE__      							=				-1
    for j in range(i + 1			,					__UpperCamelCase     ):
      if arr[i] < arr[j]:
        SCREAMING_SNAKE_CASE__      							=				arr[j]
        break
    result.append(__UpperCamelCase     )
  return result



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	list[float]     )							-> list[float]:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__      							=				[]
  for i, outer in enumerate(__UpperCamelCase     ):
    SCREAMING_SNAKE_CASE__      							=				-1
    for inner in arr[i + 1 :]:
      if outer < inner:
        SCREAMING_SNAKE_CASE__      							=				inner
        break
    result.append(__UpperCamelCase     )
  return result



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	list[float]     )							-> list[float]:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__      							=				len(__UpperCamelCase     )
  SCREAMING_SNAKE_CASE__      							=				[]
  SCREAMING_SNAKE_CASE__      							=				[-1] * arr_size

  for index in reversed(range(__UpperCamelCase     )     ):
    if stack:
      while stack[-1] <= arr[index]:
        stack.pop()
        if not stack:
          break
    if stack:
      SCREAMING_SNAKE_CASE__      							=				stack[-1]
    stack.append(arr[index]     )
  return result


if __name__ == "__main__":
   from doctest import testmod
   from timeit import timeit

   testmod()
   print(next_greatest_element_slow(arr))
   print(next_greatest_element_fast(arr))
   print(next_greatest_element(arr))

   __lowerCamelCase      :			List[Any]							       =		(
       '''from __main__ import arr, next_greatest_element_slow, '''
       '''next_greatest_element_fast, next_greatest_element'''
   )
   print(
       '''next_greatest_element_slow():''',
       timeit('''next_greatest_element_slow(arr)''', setup=setup),
   )
   print(
       '''next_greatest_element_fast():''',
       timeit('''next_greatest_element_fast(arr)''', setup=setup),
   )
   print(
       '''     next_greatest_element():''',
       timeit('''next_greatest_element(arr)''', setup=setup),
   )
