#include <bits/stdc++.h>

using namespace std;

int main() {

    int n;

    while(cin >> n, n) {

        int num[n];
        int dp[n + 1][n + 1];

        for(int i = 0; i < n; ++i) {
            cin >> num[i];
        }

        memset(dp, 0, sizeof(dp));

        for(int i = 1; i <= n; ++i) {
            for(int j = i; j <= n; ++j) {
                dp[i][j] = dp[i][j - 1] + num[j - 1];
                if(dp[i][0] < dp[i][j]) {
                    dp[i][0] = dp[i][j];
                }
            }
            if(dp[i][0] < dp[i - 1][0]) {
                dp[i][0] = dp[i - 1][0];
            }
        }

        cout << dp[n][0] << endl;

    }

}