#include <fstream>
#include <string>

using namespace std;
int gtnn=INT_MAX;
main()
{
    ifstream fi("dconmax.inp");
    ofstream fo("dconmax.out");
    int n;
    fi >> n;
    int a[n];
    for (int i = 0 ; i < n; i++) fi >> a[i];
    int b[n];
    b[-1] = a[0];
    for (int i = 0; i < n; i++) b[i] = b[i-1] + a[i];
    int mx = -2e9,gtnn = b[-1];
    for (int i = 0; i < n; i++)
    {
           mx = max(mx,b[i]-gtnn);
           gtnn=min(gtnn,b[i]);
    }
    fo << mx;
    return 0;
}

