while True:

    n = int(eval(input()))

    if n == 0:

        break

    s = [int(eval(input()))]

    for i in range(1, n):

        a = int(eval(input()))

        s.append(max(a, a + s[i - 1]))

    print((max(s)))
# -*- coding: utf-8 -*-



import sys

import os





def max_seq(A):

    s = []

    s.append(A[0])

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

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

        s.append(v)

    return max(s)



while True:

    s = input().strip()

    if s == '0':

        break



    N = int(s)

    A = []

    for i in range(N):

        v = int(eval(input()))

        A.append(v)



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

# -*- coding: utf-8 -*-
import sys
import os


def max_seq(A):
    s = []
    s.append(A[0])
    for i in range(1, len(A)):
        v = max(A[i], A[i] + s[i - 1])
        s.append(v)
    return max(s)


while True:
    s = input().strip()
    if s == "0":
        break
    N = int(s)
    A = []
    for i in range(N):
        v = int(eval(input()))
        A.append(v)
    print((max_seq(A)))

+# -*- coding: utf-8 -*- +import sys +import os + + +def max_seq(A): +    s = [] +    s.append(A[0]) +    for i in range(1, len(A)): +        v = max(A[i], A[i] + s[i - 1]) +        s.append(v) +    return max(s) + + -    n = int(eval(input())) -    if n == 0: +    s = input().strip() +    if s == "0": -    s = [int(eval(input()))] -    for i in range(1, n): -        a = int(eval(input())) -        s.append(max(a, a + s[i - 1])) -    print((max(s))) +    N = int(s) +    A = [] +    for i in range(N): +        v = int(eval(input())) +        A.append(v) +    print((max_seq(A)))