#include <iostream>

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 max = a[0];
        int S[5000];
        S[0] = a[0];
        for (int i = 1; i < n; i++)
        {
            S[i] = S[i - 1] + a[i];
        }
        for (int l = 0; l < n; l++)
        {
            for (int r = l; r < n; r++)
            {
                int sum = 0;
                if (l != 0)
                {
                    sum = S[r] - S[l - 1];
                }
                else
                {
                    sum = S[r];
                }

                if (sum > max)
                {
                    max = sum;
                }
            }
        }
        cout << max << endl;
    }
}

