import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
   import ctypes
   import msvcrt  # noqa







   class __snake_case    (						ctypes.Structure		):
      # _fields is a specific attr expected by ctypes
      lowerCAmelCase_														=							[("size", ctypes.c_int), ("visible", ctypes.c_byte)]



def      __SCREAMING_SNAKE_CASE  ( )							-> Dict:







    """simple docstring"""





    if os.name == "nt":
        SCREAMING_SNAKE_CASE__      							=				CursorInfo()
        SCREAMING_SNAKE_CASE__      							=				ctypes.windll.kernelaa.GetStdHandle(-11     )
        ctypes.windll.kernelaa.GetConsoleCursorInfo(__UpperCamelCase			,					ctypes.byref(__UpperCamelCase     )     )
        SCREAMING_SNAKE_CASE__      							=				False
        ctypes.windll.kernelaa.SetConsoleCursorInfo(__UpperCamelCase			,					ctypes.byref(__UpperCamelCase     )     )
    elif os.name == "posix":
        sys.stdout.write("""\033[?25l"""     )
        sys.stdout.flush()



def      __SCREAMING_SNAKE_CASE  ( )							-> Optional[int]:







    """simple docstring"""





    if os.name == "nt":
        SCREAMING_SNAKE_CASE__      							=				CursorInfo()
        SCREAMING_SNAKE_CASE__      							=				ctypes.windll.kernelaa.GetStdHandle(-11     )
        ctypes.windll.kernelaa.GetConsoleCursorInfo(__UpperCamelCase			,					ctypes.byref(__UpperCamelCase     )     )
        SCREAMING_SNAKE_CASE__      							=				True
        ctypes.windll.kernelaa.SetConsoleCursorInfo(__UpperCamelCase			,					ctypes.byref(__UpperCamelCase     )     )
    elif os.name == "posix":
        sys.stdout.write("""\033[?25h"""     )
        sys.stdout.flush()






@contextmanager
def      __SCREAMING_SNAKE_CASE  ( )							-> Dict:







    """simple docstring"""





    try:
        hide_cursor()
        yield
    finally:
        show_cursor()

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),
   )
