#include <iostream>
using namespace std;

int main() 
{
    int n = 0;
    int a[1000000] = {0};
    int tmp = 0;
    int max = 0;
    //接收数据
    cin >> n;
    for (int i = 0; (i < n) && (cin >> a[i]); i++);
    //求最大字串和
    tmp = max = a[0];

    for (int i = 1; i < n;)
    {
        
        if (tmp < 0)
        {
            tmp = a[i++];
        }
        else
        {
            tmp += a[i++];
        }
        if (max < tmp)
        {
            max = tmp;
        }
    }
    cout << max;
    return 0;
}