import sys



for i in sys.stdin:

    n = int(i)

    if n == 0:

        break

    max = -100000

    sum = int(eval(input()))

    for i in range(n-1):

        m = int(eval(input()))

        if sum < 0 and sum < m:

            sum = m

        elif m < 0 and max < sum:

            max = sum

            sum += m

        else:

            sum += m

    if sum > max:

        max = sum

    print(max)
import sys



s = ""

for i in sys.stdin:

    n = int(i)

    if n == 0:

        break

    max = -100000

    sum = int(input())

    for i in range(n-1):

        m = int(input())

        if sum < 0 and sum < m:

            sum = m

        else:

            if m < 0 and max < sum:

                max = sum

            sum += m

    if sum > max:

        s += str(sum) + "\n"

    else:

        s += str(max) + "\n"



print(s,end="")

import sys

for i in sys.stdin:
    n = int(i)
    if n == 0:
        break
    max = -100000
    sum = int(eval(input()))
    for i in range(n - 1):
        m = int(eval(input()))
        if sum < 0 and sum < m:
            sum = m
        elif m < 0 and max < sum:
            max = sum
            sum += m
        else:
            sum += m
    if sum > max:
        max = sum
    print(max)

import sys

s = ""
for i in sys.stdin:
    n = int(i)
    if n == 0:
        break
    max = -100000
    sum = int(input())
    for i in range(n - 1):
        m = int(input())
        if sum < 0 and sum < m:
            sum = m
        else:
            if m < 0 and max < sum:
                max = sum
            sum += m
    if sum > max:
        s += str(sum) + "\n"
    else:
        s += str(max) + "\n"
print(s, end="")

+s = "" -    sum = int(eval(input())) +    sum = int(input()) -        m = int(eval(input())) +        m = int(input()) -        elif m < 0 and max < sum: -            max = sum -            sum += m +            if m < 0 and max < sum: +                max = sum -        max = sum -    print(max) +        s += str(sum) + "\n" +    else: +        s += str(max) + "\n" +print(s, end="")