#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n;
    int A[5000];
    while (cin >> n && n)
    {
        for (int i = 0; i < n; i++)
        {
            cin >> A[i];
        }
        int S[5000];
        S[0] = A[0];
        int max = A[0];
        for (int i = 1; i < n; i++)
        {
            S[i] = S[i - 1] + A[i];
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = i; j < n; j++)
            {
                int sum = 0;
                if (i != 0)
                {
                    sum = S[j] - S[i - 1];
                }
                else
                {
                    sum = S[j];
                }
                if (max < sum)
                {
                    max = sum;
                }
            }
        }
        cout << max << endl;
    }
}
