#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> a(n);
long long ans = 0, zenyk = 0, s = 0, m = 0;
for (int& ai : a)
{
cin >> ai;
zenyk += ai;
}
for (int j = 0; j < n; j++)
{
if (m >= zenyk)
ans = max(ans, zenyk);
zenyk -= a[j];
s += a[j];
m = max(m, s);
}
cout << ans << "\n";
return 0;
}