#include <bits/stdc++.h>
//#include <iostream>
//#include <vector>
//#include <climits>
//#include <algorithm>
using namespace std;
int main(){
    int n;
    while(cin >> n){
        vector<long long> a(n);
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        long long cur=a[0];
        long long maxinum = LONG_MIN;
        for(int i = 1; i < n; i++){
            cur=a[i]+(cur>0?cur:0);
            maxinum = max(maxinum,cur);
        }
        cout << maxinum << endl;
    }
    return 0;
}