while True:

    n = int(eval(input()))

    if n == 0:

        break

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

    ans = a[0]

    for i in range(n):

        tmp = 0

        for j in range(i, n):

            tmp += a[j]

            ans = max(ans, tmp)

    print(ans)
while True:

    n = int(eval(input()))

    if n == 0:

        break

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

    minv = tmp = 0

    maxv = -500000

    for i in range(n):

        tmp += a[i]

        maxv = max(maxv, tmp - minv)

        minv = min(minv, tmp)

    print(maxv)
while True:
    n = int(eval(input()))
    if n == 0:
        break
    a = [int(eval(input())) for _ in range(n)]
    ans = a[0]
    for i in range(n):
        tmp = 0
        for j in range(i, n):
            tmp += a[j]
            ans = max(ans, tmp)
    print(ans)

while True:
    n = int(eval(input()))
    if n == 0:
        break
    a = [int(eval(input())) for _ in range(n)]
    minv = tmp = 0
    maxv = -500000
    for i in range(n):
        tmp += a[i]
        maxv = max(maxv, tmp - minv)
        minv = min(minv, tmp)
    print(maxv)

-    ans = a[0] +    minv = tmp = 0 +    maxv = -500000 -        tmp = 0 -        for j in range(i, n): -            tmp += a[j] -            ans = max(ans, tmp) -    print(ans) +        tmp += a[i] +        maxv = max(maxv, tmp - minv) +        minv = min(minv, tmp) +    print(maxv)