#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n && n) {
        int a[n + 1]; rrep(i, 1, n + 1) cin >> a[i]; a[0] = 0;
        int dp[n + 1]; dp[0] = 0;
        rrep(i, 1, n + 1) dp[i] = max(dp[i - 1] + a[i], a[i]);
        int larger = -inf;
        rrep(i, 1, n + 1) larger = max(larger, dp[i]);
        cout << larger << endl;
    }
}



