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:
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for _ in range(n)]
    a[:0] = [0]
    for i in range(1, len(a)):
        a[i] += a[i - 1]
    print(max(a) - min(a))

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

def grouping(nums):
    it = iter(nums)
    try:
        L = [next(it)]
    except StopIteration:
        return []
    minus = L[0] < 0
    for n in it:
        if (n < 0 and minus) or (n >= 0 and not minus):
            L[-1] += n
        else:
            L.append(n)
            minus = not minus
    return L

def collect(nl):
    result = 0
    if len(nl) % 2 != 0:
        nl = grouping(nl)
    while len(nl) > 0:
        if len(nl) > 1:
            nl = grouping(nl[i] + nl[i+1] for i in xrange(0, len(nl), 2))
        if len(nl) > 0 and nl[-1] <= 0:
            nl.pop()
        if len(nl) > 0 and  nl[0] >= 0:
            result += nl[0]
            nl.pop(0)
    return result

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

    L = [int(stdin.readline()) for _ in xrange(n)]
    val = max(L)
    idx = L.index(val)

    if len(L[:idx]) > 1:
        val += collect(list(reversed(L[:idx])))
    if len(L[idx+1:]) > 1:
        val += collect(L[idx+1:])

    print(val)

Python: while(1):
    a=[]
    n = int(input())
    if n==0:
        break
    a=[int(input()) for i in range(n)]
    print(sum(a))

Python: import sys

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
        elif m < 0 and max < sum:
            max = sum
            sum += m
        else:
            sum += m
    if sum > max:
        max = sum
    print(max)

Python: while True:
    n = int(input())
    if n == 0:
        break
    max_ = -999999
    a = [int(input()) for x in range(n)]
    for i in range(n):
        m = a[i]
        for j in range(i + 1, n):
            m += a[j]
            if m > max_:
                max_ = m
    print(max_)

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

    s = [0]
    for i in range(n):
        s.append(int(input()) + s[i])

    m = -100000 * 5000
    for i in range(0, n):
        for j in range(i + 1, n + 1):
            m = max(m, s[j] - s[i])

    print(m)

Python: while True:
    n = int(input())
    sumlist=[]
    max=-100000
    if n==0:
        break
    for i in range(n):
         sumlist.append(int(input()))
    sum=0
    buf=0
    for i in range(n):
        buf = sumlist[i]+buf

        if sumlist[i] > max and (buf <= 0):
            sum = 0
            max = sumlist[i]
            buf = 0

        elif buf + sum > max:
            sum = sum+buf
            max=sum
            buf = 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(1, n):
        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
    s=0
    for _ in range(n):
        i = int(input())
        if i > 0: s+=i

    print(s)

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((list))

Python: 

def solve(a_list):
    if len(list(filter(lambda x: x >= 0, a_list))) == 0:
        return max(a_list)

    dp = [0] * len(a_list)
    dp[0] = max(0, a_list[0])
    for i in range(1, len(dp)):
        dp[i] = max(0, a_list[i] + dp[i - 1])

    return max(dp)


def main():
    while True:
        n = int(input())
        if n == 0:
            break
        a_list = [int(input()) for _ in range(n)]
        print(solve(a_list))


if __name__ == '__main__':
    main()

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 len(d) <= 2:
        print(max(max(d), max(a)))
    else:
        if d[0] < 0:
            d.pop(0)
        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: while True:
    n = int(input())
    if n==0 : break

    a = []
    for i in range(n):
        a.append(int(input()))

    maxi = 0
    for i in range(1,1+n):
        for j in range(n-i+1):
            if maxi < sum(a[j:j+i]):
                maxi = sum(a[j:j+i])

    print(maxi)

Python: import sys
import math as mas

while True:
	n=int(input())
	if n==0:break
	a=[int(input()) for i in range(n)]
	ma=-100010
	for i in range(n):
		sum=0
		for j in range(i,n):
			sum+=a[j]
			ma=max(ma,sum)
	print(ma)

#for i in sys.stdin:
#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))

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

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

    a = []
    for i in range(n):
        a.append(int(input()))

    maxp = 0
    maxcont = 0

    for i in range(n):
        maxcont = max(a[i], maxcont + a[i])
        maxp = max(maxp, maxcont)

    print(maxp)

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((list))

Python: from sys import stdin

def getMax(array):
    mx = mx2 = array[0]
    for i in array[1:]:
        mx2 = max(i, mx2 + i)
        mx = max(mx, mx2)
    return mx

for line in stdin:
    n = int(line)
    if n == 0:
        break
    array = []
    for line in stdin:
        line = int(line)
        array.append(line)
        if len(array) == n:
            break
    print(getMax(array))