import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int maxSumSequence(int[] a) {
    auto dp = new int[a.length];
    dp[0] = a[0];
    for (int i = 1; i < a.length; i++) {
        dp[i] = max(dp[i - 1] + a[i], a[i]);
    }
    return dp.reduce!max;
}

void main() {
    while (true) {
        int n = readint;
        if (n == 0) break;
        int[] a;
        for (int i = 0; i < n; i++) a ~= readint;
        writeln(maxSumSequence(a));
    }
}

