n = int(input())
a = list(map(int, input().split()))
ans, zenyk, s, m = 0, 0, 0, 0
for ai in a:
zenyk += ai
for j in range(n):
if m >= zenyk:
ans = max(ans, zenyk)
zenyk -= a[j]
s += a[j]
m = max(m, s)
print(ans)