import itertools

while True:

    n = int(eval(input()))

    if n == 0:

        break

    a = [int(eval(input())) for _ in range(n)]

    a[:0] = [0]

    for i in range(1, len(a)):

        a[i] += a[i - 1]

    print((max([x[1] - x[0] for x in itertools.combinations(a, 2)])))
while True:

    n = int(eval(input()))

    if not n:

        break

    a = [int(eval(input())) for _ in range(n)]

    for i in range(1, n):

        if a[i - 1] > 0:

            a[i] += a[i - 1]

    print((max(a)))
import itertools

while True:
    n = int(eval(input()))
    if n == 0:
        break
    a = [int(eval(input())) for _ in range(n)]
    a[:0] = [0]
    for i in range(1, len(a)):
        a[i] += a[i - 1]
    print((max([x[1] - x[0] for x in itertools.combinations(a, 2)])))

while True:
    n = int(eval(input()))
    if not n:
        break
    a = [int(eval(input())) for _ in range(n)]
    for i in range(1, n):
        if a[i - 1] > 0:
            a[i] += a[i - 1]
    print((max(a)))

-import itertools - -    if n == 0: +    if not n: -    a[:0] = [0] -    for i in range(1, len(a)): -        a[i] += a[i - 1] -    print((max([x[1] - x[0] for x in itertools.combinations(a, 2)]))) +    for i in range(1, n): +        if a[i - 1] > 0: +            a[i] += a[i - 1] +    print((max(a)))