Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

Python: while True:
    t = int(input())
    if t == 0:
        break
    tmp = [int(input()) for i in range(t)]
    res = [tmp[0]]
    for i in range(1,t):
        res.append(max(tmp[i], tmp[i]+res[i-1]))

    print(max(res))

Python: while True:
	n = int(input())
	
	if n == 0:
		break
	
	res = -1111111111
	s = 0
	for i in range(n):
		a = int(input())
		s = max(s + a, 0)
		res = max(s, res)
	
	print(res)

Python: def solve():
    from sys import stdin
    f_i = stdin
    
    while True:
        n = int(f_i.readline())
        if n == 0:
            break
        
        ans = int(f_i.readline())
        s = ans
        for i in range(n - 1):
            if s > 0:
                s += int(f_i.readline())
            else:
                s = int(f_i.readline())
            if s > ans:
                ans = s
        print(ans)

solve()

Python: while True:
	n = int(input())
	
	if n == 0:
		break
	
	res = 0
	s = 0
	for i in range(n):
		a = int(input())
		s = max(s + a, 0)
		res = max(s, res)
	
	print(res)

Python: """
全探索１　O(n^3)
while 1:
    a = []
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for i in range(n)]
    max = 0
    for i in range(n):
        for j in range(i, n):
            sum = 0
            for k in range(i, j+1):
                sum += a[k]
            if max < sum:
                max = sum
    print(max)
"""
while 1:
    a = []
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for i in range(n)]
    max = -111111111111111
    for i in range(n):
        sum = 0
        for j in range(i, n):
            sum += a[j]
            if sum > max:
                max = sum

    print(max)

Python: while True:
    n = int(input())
    m = -1000000 
    if n == 0:
        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)

Python: import sys

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

    for i in range(len(a)+1):
        for j in range(i, len(a)+1):
            sums.append(sum(a[i:j]))

    print(max(sums))

Python: import math

def sign(x):
    if x >= 0:
        return True
    else:
        return False

n = int(input())
while n != 0:
    a = []
    for i in range(n):
        a.append(int(input()))
    b = []
    b.append(a[0])
    for i in range(1,len(a)):
        if sign(b[len(b)-1]) == sign(a[i]):
            b[len(b)-1] = b[len(b)-1] + a[i]
        else:
            b.append(a[i])

    ans = b[0]
    for i in range(len(b)):
        S = 0
        for j in range(i,len(b)):
            S = S + b[j]
            ans = max(S, ans)
    print(ans)
    n = int(input())

Python: import sys

n = int(sys.stdin.readline())
while n:
    l = list()
    for _ in range(n):
        l.append(int(input()))
    a = l.copy()
    for i in range(1,n):
        a[i] = max(a[i-1] + l[i], l[i])
    print(max(a))
    n = int(sys.stdin.readline())

Python: while 1:
	n=int(input())
	if n==0: break
	a=[int(input()) for i in range(n)]
	temp = 0
	most = -999999999
	for i in range(n):
		temp = 0
		for j in range(i,n):
			temp +=	a[j]
			if temp > most:
				most = temp
	print(most)

Python: while True:
    num = int(input())
    if not num: break
    result, tmp = 0, 0
    for _ in range(num):
        new = int(input())
        tmp = max(new, new+tmp)
        result = max(tmp, result)
        print(new, tmp, result)
    if tmp < 0:
        result = tmp
    print(result)

Python: #!/usr/bin/python

from sys import stdin

def datasets():
    raw_input()
    for l in stdin:
        yield int(l)
        
def main():
    ds = datasets()
    first = next(ds)
    lastnum = count = maximum = first
    for n in ds:
        if n == lastnum:
            count += n
        else:
            if count > maximum:
                maximum = count
            count = n
        lastnum = n
        
if __name__ == '__main__':
    main()

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

Python: while(1):
    n = int(input())
    if n == 0:
        break
    else:
        ary = []
        mx = 0
        for i in range(n):
            ary.append(int(input()))
        for i in range(1, n + 1):
            sm = sum(ary[0:i])
            if mx < sm:
                mx = sm
            for j in range(1, n - i + 1):
                sm = sm - ary[j - 1] + ary[j + i - 1]
                if mx < sm:
                    mx = sm
        print(mx)

Python: while True:
    n = int(input())
    if n==0: break
    sum_li = [int(input()) for i in range(n)]
    for i in range(2,n+1):
        for j in range(n-i+1):
            sum_li.append(sum(sum_li[j:j+i]))
    print(sorted(sum_li)[-1])

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

Python: def maximumSubArray(array):
    n = len(array)
    dp = [0]*n # dp[i]: i番目までの全ての部分配列の中の最大の総和
    dp[0] = array[0]
    for i in range(1, n):
        dp[i] = max(dp[i - 1] + array[i], array[i])
    return max(dp)

while True:
    n = int(input())
    a = []
    if n == 0:
        break
    for _ in range(n):
        a.append(int(input()))
    print(maximumSubArray(a))

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


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

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

        print(max_sum_sequence(data))


def max_sum_sequence(data):
    max = 0
    num_data = len(data)
    for l in xrange(num_data + 1):
        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)

    first = 0
    before = None

    for begin in xrange(num_data):
        sum = 0
        if begin > 0:
            first = data[begin - 1]

        if before is None:
            for i in xrange(begin, begin + length):
                if i >= num_data:
                    continue

                sum += data[i]

        else:
            if begin + length + 1 < num_data:
                sum = before - first + data[begin + length + 1]
            else:
                sum = before - first;

        before = sum

        if sum > max:
            max = sum

    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(1,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: while True:
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for _ in range(n)]
    b = []
    while a != []:
        for i in range(len(a)):
            if i == len(a) - 1 or a[i] * a[i + 1] < 0:
                b.append(sum(a[:i + 1]))
                a[:i + 1] = []
                break
    print(max(max(sum(b[j:j + i + 1]) for j in range(len(b) - i)) for i in range(len(b))))