

while 1:

    n = eval(input())

    if n == 0:

        break

    A = []

    for i in range(n):

        A.append(int(input()))

    dp = [0] * len(A)

    dp[0] = A[0]

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

        dp[i] = max(dp[i - 1] + A[i], A[i])

    print(max(dp))
while 1:

    n = int(input())

    if n == 0:

        break

    A = [0] * n

    for i in range(n):

        A[i] = int(input())

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

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

    print(max(A))
while 1:
    n = eval(input())
    if n == 0:
        break
    A = []
    for i in range(n):
        A.append(int(input()))
    dp = [0] * len(A)
    dp[0] = A[0]
    for i in range(1, len(A)):
        dp[i] = max(dp[i - 1] + A[i], A[i])
    print(max(dp))

while 1:
    n = int(input())
    if n == 0:
        break
    A = [0] * n
    for i in range(n):
        A[i] = int(input())
    for i in range(1, len(A)):
        A[i] = max(A[i - 1] + A[i], A[i])
    print(max(A))

-    n = eval(input()) +    n = int(input()) -    A = [] +    A = [0] * n -        A.append(int(input())) -    dp = [0] * len(A) -    dp[0] = A[0] +        A[i] = int(input()) -        dp[i] = max(dp[i - 1] + A[i], A[i]) -    print(max(dp)) +        A[i] = max(A[i - 1] + A[i], A[i]) +    print(max(A))