#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll ;
const int maxn=1000001;
ll dp[maxn];
ll a[maxn];
void init(){
    memset(dp, 0, sizeof(dp));
    memset(a,0,sizeof(a));
}
int main() {
    int n;
    while(cin>>n){
        init();
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        dp[0]=a[0];
        ll m=-1000;
        for(int i=1;i<n;i++){
            dp[i]=max(dp[i-1]+a[i], a[i]);
            if(dp[i]>m) m=dp[i];
        }
        cout<<m<<endl;
    }
}