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 True:
    num = int(input())

    if num == 0: 
        break
    
    list = []
    for i in range(num):
        list.append(int(input()))

    for i in range(1, num):
        list[i] = max(list[i - 1] + list[i], list[i])

    print(max(list))

Python: while 1:
    m=0
    l=[]
    n=int(input())
    if not n: break
    for i in range(n):
        j=int(input())
        if i==0:
            m+=j
        elif s*j<0:
            l.extend([m])
            m=j
        else:
            m+=j
        s=j
    l.extend([m])
    b=len(l)
    print(max([sum(l[i:j]) for j in range(1,b+1) for i in range(j)]))

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

while True:
    n = int(input())
    if n == 0:
        break
    a = []
    for i in range(0,n):
        a.append(int(input()))
    sumMax = -100000
    for i in range(0,n):
        tmp = 0
        for j in range(i,n):
            tmp += a[j]
            sumMax = max(sumMax,tmp)
    print(sumMax)

Python: n = int(input())
while n > 0:
    s = []
    m = 0
    for i in range(n):
        m += int(input())
        s.append(m)
    print(max(s))
    n = int(input())

Python: while True:
    n=int(input())
    if n==0:
        break
    a=[int(input()) for i in range(n)]
    MAX=0
    SUM=0
    for i in a:
        SUM+=i
        MAX=max(MAX,SUM)
        if SUM<0:
            SUM=0
    print(MAX)

Python: while True:
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for _ in range(n)]
    d = [a[0]]
    for i in range(n):
        if d[0] == 0:
            d[0] += a[i]
        if a[i] / d[-1] >= 0:
            d[-1] += a[i]
        else:
            d.append(a[i])
    for i in range(2, len(d)):
        if d[i - 1] < 0 and d[i -2] > d[i - 1] and d[i] > d[i - 1]:
            d[i] += d[i -2] + d[i -1]
    print(max(d))

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

Python: while True:
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for _ in range(n)]
    d = [a[0]]
    for i in range(n):
        if d[0] == 0:
            d[0] += a[i]
        elif a[i] / d[-1] >= 0:
            d[-1] += a[i]
        else:
            d.append(a[i])
    if d[0] < 0:
        d.pop(0)
    if d == []:
        print(max(a))
    if len(d) <= 2:
        print(max(d))
    else:
        maxd = max(d)
        for i in range(0, len(d), 2):
            for j in range(i + 1, len(d) + 1, 2):
                maxd = max(maxd, sum(d[i:j]))
        print(maxd)

Python: n=int(input())
while(n!=0):
    index=0
    list=[]
    sum=0
    max=0
    break_flag=False
    for i in range(n):
        list.append(int(input()))
    max=list[0]
    while (index < len(list) and list[index] < 0):
        if max<list[index]: max = list[index]
        index += 1

    if index==len(list):
        print(max)
        break_flag=True

    if not break_flag:
        while (index < len(list) and list[index] >= 0):
            sum += list[index]
            index += 1

        if sum>=0: max=sum

        while(index<len(list)):
            plus_sum = 0
            minus_sum = 0

            while (index < len(list) and list[index] < 0):
                minus_sum += list[index]
                index += 1

            while (index < len(list) and list[index] >= 0):
                plus_sum += list[index]
                index += 1

            if abs(minus_sum)<plus_sum:
                sum+=(minus_sum+plus_sum)
                if max<sum: max=sum
            else:
                sum=plus_sum
                if max<sum: max=sum
        print(max)
    n=int(input())

Python: while 1:
    n=input()
    if n==0:
        break
    else:
        a=[input() for _ in xrange(n)]
        ans=-float('inf')
        for i in xrange(n):
            for j in xrange(i,n):
                if ans<sum(a[i:j+1]):
                    ans=sum(a[i:j+1])
        print(ans)

Python: # INF = float("inf")
import sys,bisect
sys.setrecursionlimit(15000)

st = []
ar = 0
while True:
   n = int(sys.stdin.readline())
   if n == 0:
     break
   a = [int(sys.stdin.readline()) for _ in range(n)]
   ml = mg = a[0]
   #print(a)
   for i in range(1,n):
     ml = max(ml+a[i],a[i])
     mg = max(mg,ml)
     #print(ml,mg,a[i])
   print(mg)

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

Python: from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from sys import stdin

while True:
    n = int(stdin.readline())
    if not n:
        break

    tup = tuple(int(stdin.readline()) for _ in xrange(n))
    L = [tup[0]]
    for i in tup[1:]:
        if 0 > i and 0 > L[-1]:
            L[-1] += i
        elif 0 <= i and 0 <= L[-1]:
            L[-1] += i
        else:
            L.append(i)

    while True:
        length = len(L)
        if length > 1 and L[0] <= 0:
            L.pop(0)
            continue
        if length > 1 and L[-1] <= 0:
            L.pop()
            continue
        if length > 1 and L[0] + L[1] <= 0:
            L.pop(0)
            L.pop(0)
            continue
        if length > 1 and L[-1] + L[-2] <= 0:
            L.pop()
            L.pop()
            continue
        break
    print(L)

    m = 0
    for i in xrange(len(L)):
        for j in xrange(1 + i, len(L) + 1):
            t = sum(L[i:j])
            if t > m:
                m = t
    print(m)

Python: while True:
    n = int(input())
    if n == 0:
        break
    dp = [int(input())]
    for i in range(1, n):
        a_i = int(input())
        dp.append(max(dp[i - 1] + a_i, a_i))
    print(max(dp))

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

Python: while True:
    n=int(input())
    if n == 0:
        break

    ans=0
    l=[]

    for _ in range(n):
        l.append(int(input()))
    for i in range(n):
        s=0
        for j in range(i,n):
            s+=l[j]
            if ans < s: ans = s
    print(ans)

Python: while True:
    n = int(input())
    if n == 0:
        quit()
    a = []
    for i in range(n):
        a.append(int(input()))
    mn = -100001
    for i in range(len(a)):
        temp = a[i]
        mn = max(mn, temp)
        for j in range(i+1, len(a)):
            temp += a[j]
            mn = max(mn, temp)
    print(mn)