Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

Python: while 1:
    try:
        n = int(input())
    except:break
    
    if(n == 0):break

    sum = 0
    arr = []
    isPlus = True
    maxValue = -100000
    for i in range (n):
        try:
            arr.append(int(input()))  
        except:break
           
        if arr[i] < 0:
            # 合計が0以下になってしまった場合はこれ以上計算しても意味がないのでスルーする
            if sum > 0:
                # plusが連続して続いていた場合
                if(isPlus):
                    # 最大値を更新
                    maxValue = max(maxValue,sum)
                    isPlus = False
                sum += arr[i]
                # 0未満になったら、1から計算し直す
                if sum < 0 :
                    sum = 0
        else :
            sum += arr[i]
            isPlus = True
    if sum != 0 :
        maxValue = max(maxValue,sum)
    # 入力値が全てminusなので、入力値から最大のものを探す    
    else :
        for i in arr:
            maxValue = max(maxValue,i)
    print(maxValue)

Python: while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		A.append(int(input()))
	end=len(A)
	MAX=[0]*end
	for i in range(end):
		for j in range(i+1,end+1):
			s=sum(A[i:j])
			if MAX[i]<s:
				MAX[i]=s
	print(max(MAX))

Python: # -*- coding: utf-8 -*-

import sys
import os


def max_seq(A):
    acc = max(0, A[0])
    ans = max(0, A[0])

    for i in range(1, len(A)):
        v = acc + A[i]
        if v < 0:
            # ???????????§???????????????acc??????????¶???????????????????
            ans = max(ans, acc)
            # ????????????
            acc = max(0, A[i])
        else:
            acc = v
            ans = max(ans, acc)
    return ans

while True:
    s = input().strip()
    if s == '0':
        break

    N = int(s)
    A = []
    for i in range(N):
        v = int(input())
        A.append(v)

    print(max_seq(A))

Python: # -*- 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(input())
        A.append(v)

    print(max_seq(A))

Python: while True:
    n=int(input())
    if n==0:break
    l=[int(input()) for i in range(n)]
    s=0
    m=0
    for li in l:
        s=max(0,s+li)
        m=max(m,s)
    print(m if m else max(l))

Python: while True:
    n = int(input())
    if n == 0:
        break
    sum_max = 0
    a = []
    for i in range(n):
        a.append(int(input()))
        for j in range(i + 1):
            sum_tmp = sum(a[j:i + 1])
            if sum_tmp > sum_max:
                sum_max = sum_tmp
    print(sum_max)

Python: while 1:
    n=int(input())
    if not n:break
    l=tuple([int(input()) for _ in range(n)])
    print(max(sum(l[j:i]) for i in range(len(l)+1) for j in range(i)))

Python: #!/usr/bin/python
# -*- coding: utf-8 -*-

import sys


def main():
    while True:
        try:
            num_data = int(raw_input())
            if num_data == 0:
                break

            data = []
            for i in xrange(num_data):
                data.append(int(raw_input()))

            max = max_sum_sequence(data)
            print(max)
        except:
            break


def max_sum_sequence(data):
    max = 0
    num_data = len(data)
    for l in xrange(1, num_data + 1):
        #print ("testing at l = " + str(l) + "..")
        sum = max_at_length(data, l)
        if sum > max:
            max = sum

    return max


def max_at_length(data, length):
    max = 0
    num_data = len(data)

    sum = None
    old_head = 0

    #print "length = " + str(length)

    while True:
        if sum is None:
            sum = 0
            for i in xrange(0, length):
                sum += data[i]
            #print "initial = " + str(sum)
            max = sum

        else:
            if old_head + length < num_data:
                #print "sum = %d - %d + %d" % (sum, data[old_head], data[old_head + length])
                sum = sum - data[old_head] + data[old_head + length]
                #print "     = " + str(sum)
                if sum > max:
                    max = sum

                old_head += 1
            else:
                break

    return max

main()

Python: while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		x=int(input())
		A.append(x)

	B=[int()]*n
	B[0]=A[0]
	for i in range(n):
		if A[i]>=A[i]+B[i-1]:
			B[i]=A[i]
		else:
			B[i]=A[i]+B[i-1]
	print(max(B))

Python: import sys

def solve(numbers):
    max = -sys.maxsize
    for i in range(0, len(numbers)):
        sum = 0
        for j in range(i, len(numbers)):
            sum += numbers[j]
            if sum > max:
                max = sum
    return max


while True:
    n = int(input())
    if n == 0:
        break
    numbers = []
    for i in range(0, n):
        numbers.append(int(input()))

    print(solve(numbers))

Python: while True:
    n = int(input())
    if n == 0:
        break
    else:
        A = []
        Sum = []
        for i in range(n):
            A.append(int(input()))
        Wa = 0
        for i in range(0,n):
            Wa += A[i]
            Sum.append(Wa)
        for i in range(0 , n):
            for j in range(0 , i):
                Num = Sum[i] - Sum[j]
                Sum.append(Num)
        print(max(Sum))

Python: if __name__ == '__main__':
    while True:
        # ??????????????\???
        loop = int(input())
        if loop == 0:
            break
        data = [int(input()) for _ in range(loop)]

        # ???????????????
        max_total = max(data)  # ??£?¶?????????°???????????§????¨????
        total = 0
        for d in data:
            if d > 0:  # ??°??????+??§????????°?????±????°????
                total += d  # ????¨?????¶???????????¨?????????´??°????????????????¢????????????????
                if total > max_total:
                    max_total = total
            else:  # ??°??????-?????´?????????????????§????????£???????????????????????§??????????????????
                if total > abs(d):  # ???????????§??????????????????????????§????????°???total???????????????????¶??¶???????
                    total += d
                    # ???????????????????????????????????§???max_total?????´??°??????????????§?????????
                else:
                    total = 0  # ???????????????????????§??????????????????????????§??????????????§????¨??????????????????????????¬??????????????????????????????????

        # ???????????¨???
        print(max_total)

Python: import sys

while 1:
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for _ in range(n)]
    sumMax = 0

    for i in range(len(a)+1):
        for j in range(i, len(a)+1):
            if sum(a[i:j]) > 0:
                sumMax = sum(a[i:j])

    print(sumMax)

Python: while True:
 try:
  n=int(input())
  a=[int(input()) for i in range(n)]
  print(max(a))
 except EOFError:
  break

Python: while True:
    n = int(input())
    m = -1000000 
    if not n :
        break
    dataset = [int(input()) for _ in range(n)]
    for i in range(n):
        for j in range(i, n + 1):
            if dataset[i:j] != []:
                s = sum(dataset[i:j])
                if m < s:
                    m = s
    print(m)