






from __future__ import annotations

UpperCAmelCase__				   =		[-10, -5, 0, 5, 5.1, 11, 13, 21, 3, 4, -21, -10, -5, -1, 0]
UpperCAmelCase__				   =		[-5, 0, 5, 5.1, 11, 13, 21, -1, 4, -1, -10, -5, -1, 0, -1]
def 						_a    (      a :list[float] )							->			list[float]:
 a		  =      []
 a		  =      len(a )

 for i in range(a ):
  a		  =      -1
  for j in range(i + 1	,							a ):
   if arr[i] < arr[j]:
    a		  =      arr[j]
    break
  result.append(a )
 return result
def 						_a    (      a :list[float] )							->			list[float]:
 a		  =      []
 for i, outer in enumerate(a ):
  a		  =      -1
  for inner in arr[i + 1 :]:
   if outer < inner:
    a		  =      inner
    break
  result.append(a )
 return result
def 						_a    (      a :list[float] )							->			list[float]:
 a		  =      len(a )
 a		  =      []
 a		  =      [-1] * arr_size

 for index in reversed(range(a ) ):
  if stack:
   while stack[-1] <= arr[index]:
    stack.pop()
    if not stack:
     break
  if stack:
   a		  =      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))

     UpperCAmelCase__				   =		(
         "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),
     )



"""simple docstring"""






from collections.abc import Sequence



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase       ,    __UpperCAmelCase = False )  ->  float:
   if not arr:
      return 0

   lowercase__:   Any					=      0 if allow_empty_subarrays else float('''-inf''' )
   lowercase__:   Union[str, Any]					=      0.0
   for num in arr:
      lowercase__:   List[str]					=      max(0 if allow_empty_subarrays else num       ,    curr_sum + num )
      lowercase__:   int					=      max(__UpperCAmelCase       ,    __UpperCAmelCase )

   return max_sum


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

       testmod()

       __A			   = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
       print(f'''{max_subarray_sum(nums) = }''')
