#用前缀和暴力求解,9/12的通过率
n = int(input())
l = list(map(int, input().split()))
for i in range(1, len(l)):
l[i] = l[i - 1] + l[i]
if n == 1:
print(l[0])
else:
dp = [l[0]]
for i in range(1, len(l)):
dp.append(l[i])
for j in range(i):
dp.append(l[i] - l[j])
print(max(dp))