
from collections.abc import Sequence






def 		_UpperCAmelCase   (	UpperCamelCase:     Sequence[float]			,							UpperCamelCase:     bool = False  ):






	"""simple docstring"""


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

	return max_sum


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

					testmod()

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






from __future__ import annotations

from math import ceil, floor, sqrt






def 		_UpperCAmelCase   (	UpperCamelCase:     int = 2_0_0_0_0_0_0  ):






	"""simple docstring"""


	__lowerCAmelCase         =							[0]
	__lowerCAmelCase         =							42

	for idx in range(1			,							ceil(sqrt(target * 2  ) * 1.1  )  ):
		triangle_numbers.append(triangle_numbers[-1] + idx  )

	# we want this to be as close as possible to target
	__lowerCAmelCase         =							0
	# the area corresponding to the grid that gives the product closest to target
	__lowerCAmelCase         =							0
	# an estimate of b, using the quadratic formula
	__lowerCAmelCase         =							42
	# the largest integer less than b_estimate
	__lowerCAmelCase         =							42
	# the largest integer less than b_estimate
	__lowerCAmelCase         =							42
	# the triangle number corresponding to b_floor
	__lowerCAmelCase         =							42
	# the triangle number corresponding to b_ceil
	__lowerCAmelCase         =							42

	for idx_a, triangle_a in enumerate(triangle_numbers[1:]			,							1  ):
		__lowerCAmelCase         =							(-1 + sqrt(1 + 8 * target / triangle_a  )) / 2
		__lowerCAmelCase         =							floor(UpperCamelCase  )
		__lowerCAmelCase         =							ceil(UpperCamelCase  )
		__lowerCAmelCase         =							triangle_numbers[b_floor]
		__lowerCAmelCase         =							triangle_numbers[b_ceil]

		if abs(target - triangle_b_first_guess * triangle_a  ) < abs(
		    target - best_product  ):
			__lowerCAmelCase         =							triangle_b_first_guess * triangle_a
			__lowerCAmelCase         =							idx_a * b_floor

		if abs(target - triangle_b_second_guess * triangle_a  ) < abs(
		    target - best_product  ):
			__lowerCAmelCase         =							triangle_b_second_guess * triangle_a
			__lowerCAmelCase         =							idx_a * b_ceil

	return area


if __name__ == "__main__":
					print(f'''{solution() = }''')






