





def   a_   (			lowerCAmelCase_				:      Union[str, Any],     lowerCAmelCase_				:      Optional[Any]     ):
   __lowerCAmelCase							     =     [1]
   for i in range(2,     lowerCAmelCase_     ):
      factorials.append(factorials[-1] * i     )
   assert 0 <= k < factorials[-1] * n, "k out of bounds"

   __lowerCAmelCase							     =     []
   __lowerCAmelCase							     =     list(range(lowerCAmelCase_     )     )

   # Find permutation
   while factorials:
      __lowerCAmelCase							     =     factorials.pop()
      __lowerCAmelCase     ,     __lowerCAmelCase							     =     divmod(lowerCAmelCase_,     lowerCAmelCase_     )
      permutation.append(elements[number]     )
      elements.remove(elements[number]     )
   permutation.append(elements[0]     )

   return permutation


if __name__ == "__main__":
     import doctest

     doctest.testmod()








from collections.abc import Sequence

def   a_   (			lowerCAmelCase_				:      Sequence[float],     lowerCAmelCase_				:      bool = False     ):
   if not arr:
      return 0

   __lowerCAmelCase							     =     0 if allow_empty_subarrays else float('-inf'     )
   __lowerCAmelCase							     =     0.0
   for num in arr:
      __lowerCAmelCase							     =     max(0 if allow_empty_subarrays else num,     curr_sum + num     )
      __lowerCAmelCase							     =     max(lowerCAmelCase_,     lowerCAmelCase_     )

   return max_sum


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

     testmod()

     _snake_case  :   Optional[Any]						   =  [-2, 1, -3, 4, -1, 2, 1, -5, 4]
     print(F"""{max_subarray_sum(nums) = }""")

