



'''simple docstring'''


def  UpperCAmelCase_       (		lowercase__       ):


					'''simple docstring'''







					a_       		=0
					a_       		=len(lowercase__       )

					for i in range(n - 1       ):
										for j in range(i + 1       ,	lowercase__       ):
															if arr[i] > arr[j]:
																				num_inversions += 1

					return num_inversions






def  UpperCAmelCase_       (		lowercase__       ):


					'''simple docstring'''







					if len(lowercase__       ) <= 1:
										return arr, 0
					a_       		=len(lowercase__       ) // 2
					a_       		=arr[0:mid]
					a_       		=arr[mid:]

					a_		,						a_       		=count_inversions_recursive(lowercase__       )
					a_		,						a_       		=count_inversions_recursive(lowercase__       )
					a_		,						a_       		=_count_cross_inversions(lowercase__       ,	lowercase__       )

					a_       		=inversion_p + inversions_q + cross_inversions
					return c, num_inversions






def  UpperCAmelCase_       (		lowercase__       ,	lowercase__       ):


					'''simple docstring'''







					a_       		=[]
					a_       		=a_       		=a_       		=0
					while i < len(lowercase__       ) and j < len(lowercase__       ):
										if p[i] > q[j]:
															# if P[1] > Q[j], then P[k] > Q[k] for all  i < k <= len(P)
															# These are all inversions. The claim emerges from the
															# property that P is sorted.
															num_inversion += len(lowercase__       ) - i
															r.append(q[j]       )
															j += 1
										else:
															r.append(p[i]       )
															i += 1

					if i < len(lowercase__       ):
										r.extend(p[i:]       )
					else:
										r.extend(q[j:]       )

					return r, num_inversion






def  UpperCAmelCase_       (		):


					'''simple docstring'''







					a_       		=[1_0, 2, 1, 5, 5, 2, 1_1]

					# this arr has 8 inversions:
					# (10, 2), (10, 1), (10, 5), (10, 5), (10, 2), (2, 1), (5, 2), (5, 2)

					a_       		=count_inversions_bf(lowercase__       )
					a_		,						a_       		=count_inversions_recursive(lowercase__       )

					assert num_inversions_bf == num_inversions_recursive == 8

					print("number of inversions = "       ,	lowercase__       )

					# testing an array with zero inversion (a sorted arr_1)

					arr_a.sort()
					a_       		=count_inversions_bf(lowercase__       )
					a_		,						a_       		=count_inversions_recursive(lowercase__       )

					assert num_inversions_bf == num_inversions_recursive == 0
					print("number of inversions = "       ,	lowercase__       )

					# an empty list should also have zero inversions
					a_       		=[]
					a_       		=count_inversions_bf(lowercase__       )
					a_		,						a_       		=count_inversions_recursive(lowercase__       )

					assert num_inversions_bf == num_inversions_recursive == 0
					print("number of inversions = "       ,	lowercase__       )


if __name__ == "__main__":
		main()







'''simple docstring'''


from collections.abc import Sequence






def  UpperCAmelCase_       (		lowercase__ = None       ):


     '''simple docstring'''







     if nums is None or not nums:
          raise ValueError("Input sequence should not be empty"       )

     a_       		=nums[0]
     for i in range(1       ,	len(lowercase__       )       ):
          a_       		=nums[i]
          a_       		=max(lowercase__       ,	ans + num       ,	lowercase__       )

     return ans


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  # Try on a sample input from the user
  lowercase							       =			int(input('''Enter number of elements : ''').strip())
  lowercase							       =			list(map(int, input('''\nEnter the numbers : ''').strip().split()))[:n]
  print(max_subsequence_sum(array))


