#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+14;
long long n, sum = 0, minres = 0, ans = -1e18;
void solve(){
cin >> n;
for (int i = 1; i <= n; i++){
int x;
cin >> x;
minres = min(minres, sum);
sum += x;
ans = max(ans, sum - minres);
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen("input.txt","r")) {
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBtYXhuPTFlNisxNDsKbG9uZyBsb25nIG4sIHN1bSA9IDAsIG1pbnJlcyA9IDAsIGFucyA9IC0xZTE4Owp2b2lkIHNvbHZlKCl7CgljaW4gPj4gbjsKCWZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKyl7CgkJaW50IHg7CgkJY2luID4+IHg7CQogICAgICAgIG1pbnJlcyA9IG1pbihtaW5yZXMsIHN1bSk7CgkJc3VtICs9IHg7CgkJYW5zID0gbWF4KGFucywgc3VtIC0gbWlucmVzKTsKCX0KCQoJY291dCA8PCBhbnM7Cn0KaW50IG1haW4oKXsKCWlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CgljaW4udGllKDApOyAgICBjb3V0LnRpZSgwKTsKICAgIGlmIChmb3BlbigiaW5wdXQudHh0IiwiciIpKSB7CiAgICAgICAgZnJlb3BlbigiaW5wdXQudHh0IiwiciIsc3RkaW4pOwogICAgICAgIGZyZW9wZW4oIm91dHB1dC50eHQiLCJ3IixzdGRvdXQpOwogICAgfQoJc29sdmUoKTsKCXJldHVybiAwOwp9Cg==