#include <iostream>
#include <cstdio>
using namespace std;
int main(int argc, const char * argv[])
{
    while (1) {
        int n; scanf("%d", &n);
        if (n == 0) break;
        long int a[n], b[n], tmp = 0;
        for (int i = 0; i < n; i++) {
            scanf("%ld", &a[i]);
            b[i] = 0;
        }
        for (int i = 0; i < n; i++) {
            for (int k = 0; k <= i; k++) {
                b[i] += a[k];
            }
        }
        for (int i = n-1; i > 0; i--) {
            for (int k = i-1; k >= 0; k--) {
                if (i == n-1) {
                    tmp = (b[i] - b[k] + a[k]);
                }
                if (tmp < (b[i] - b[k] + a[k])) {
                    tmp = (b[i] - b[k] + a[k]);
                }
            }
        }
        cout << tmp << endl;
    }
    return 0;
}