#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll t, n, m, k, l, r, op, x, y;
const ll inf = 0x3f3f3f3f3f3f3f3f;
bool flag ;
void solve() {
y = m = -inf;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> k;
if (k < 0)m = max(m, k);
if (k > 0)flag = true;
x = max(x + k, 0LL);
y = max(y, x);
}
if (!flag)cout << m;
else cout << y;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}