import itertools



while True:

    n = int(eval(input()))

    if n == 0:

        break

    else:

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

        a = list(itertools.accumulate(a))

        a.insert(0, 0)

        ans = -100000

        for j in range(n):

            for k in range(j + 1, n + 1):

                ans = max(ans, a[k] - a[j])

        print(ans)
while True:

    n = int(eval(input()))

    if n == 0:

        break

    else:

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

        for i in range(1, n):

            a[i] = max(a[i - 1] + a[i], a[i])

        print((max(a)))
import itertools

while True:
    n = int(eval(input()))
    if n == 0:
        break
    else:
        a = [int(eval(input())) for i in range(n)]
        a = list(itertools.accumulate(a))
        a.insert(0, 0)
        ans = -100000
        for j in range(n):
            for k in range(j + 1, n + 1):
                ans = max(ans, a[k] - a[j])
        print(ans)

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

-import itertools - -        a = list(itertools.accumulate(a)) -        a.insert(0, 0) -        ans = -100000 -        for j in range(n): -            for k in range(j + 1, n + 1): -                ans = max(ans, a[k] - a[j]) -        print(ans) +        for i in range(1, n): +            a[i] = max(a[i - 1] + a[i], a[i]) +        print((max(a)))