#include <iostream>
using namespace std;

const int N = 1000010;
typedef long long LL;
LL a[N];
LL f[N];
int main() {
    int n;
    while (cin >> n) {
        //f[i]是以a[i]结尾的子序列并不是i取到n,f[i]就是最大的
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        LL res = a[0];
        f[0] = 0;
        for (int i = 1; i <= n; i++) {
            f[i] = max(f[i-1], (LL)0) + a[i];
            res = max(f[i], res);

        }
        cout << res << endl;
    }

}