import sys

n = int(input())
lis = list(map(int,input().split()))

max_value = sum_value = lis[0]
for x in lis[1:]:
    sum_value = max(x,sum_value+x)
    if sum_value>max_value:
        max_value = sum_value
print(max_value)