Go: package main

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

var infty = 100000 * 2
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	scanner.Scan()
	return strconv.Atoi(scanner.Text())
}

func findMaximumSubarray(arr []int) int {
	currentMaxSum, maxSumContainsTail := -infty, -infty

	for j := range arr {
		if arr[j] > maxSumContainsTail+arr[j] {
			maxSumContainsTail = arr[j]
		} else {
			maxSumContainsTail += arr[j]
		}
		if currentMaxSum < maxSumContainsTail {
			currentMaxSum = maxSumContainsTail
		}

		// fmt.Println(arr[j], currentMaxSum, maxSumContainsTail)
	}
	return currentMaxSum
}

func main() {
	scanner.Split(bufio.ScanWords)
	for {
		size, _ := nextInt()
		if size == 0 {
			break
		}

		arr := make([]int, size)
		for i := range arr {
			n, _ := nextInt()
			arr[i] = n
		}

		maximumSum := findMaximumSubarray(arr)
		fmt.Println(maximumSum)
	}
}

Python: while True:
    n = int(input())
    if n == 0:
        break
    cum = [0]
    s = 0
    for i in range(n):
        s += int(input())
        cum.append(s)
    M = cum[1]
    for i in range(n):
        for j in range(i + 1, n + 1):
            if cum[j] - cum[i] > M:
                M = cum[j] - cum[i]
    print(M)

Python: while True:
  n = int(input())
  if n == 0:
    break
  acc = int(input())
  min_n = min(0, acc)
  max_n = max(0, acc)
  ans = acc
  for _ in range(n - 1):
    acc += int(input())
    min_n = min(min_n, acc)
    max_n = max(max_n, acc)
    ans = max(ans, max_n - min_n)
  print(ans)

Python: import itertools

while True:
    n = int(input())
    if n == 0:
        break
    else:
        a = [int(input()) for i in range(n)]
        a = list(itertools.accumulate(a))
        a.insert(0, 0)
        ans = -1000000
        for j in range(n + 1):
            for k in range(n + 1):
                ans = max(ans, a[k] - a[j])
        print(ans)

Python: while True:
    n = int(input())

    if n == 0:
        break

    dp = []

    for _ in range(n):
        if len(dp) == 0:
            dp.append(int(input()))
        else:
            x = int(input())
            dp.append(max(dp[-1] + x, x))

    print(max(dp))

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

    a = [int(input()) for _ in range(n)]
    s = 0
    result = -1000000

    for i in range(n):
        s = 0
        for j in range(i, n):
            s += a[j]
            result = max(s, result)
    print(result)

Python: from itertools import accumulate, combinations
while True:
    n = int(input())
    if n == 0:
        break
    L = [None]*n
    for i in range(n):
        L[i] = int(input())

    M = []
    M.append(0)
    M.extend(list(accumulate(L)))
    K = [ M[j] - M[i] for i, j in combinations(range(n+1),2)]
    print(max(K))

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

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

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, a)
        res = max(s, res)
     
    print(res)

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

n = []
a = []

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

count = 0
for i in range(0,len(n)):
    sumMax = 0
    for j in range(count,count + n[i]):
        tmp = a[j]
        for k in range(j,count + n[i]):
            if j==k:
                continue
            tmp += a[k]
            sumMax = max(sumMax,tmp)
    count += n[i]
    print(sumMax)

Python: m=lambda x:max(map(max,[[sum(x[j:j+i+1]) for j in range(len(x)-i)] for i in range(len(x))]))
while True:
    n=int(input())
    if n==0:break
    print(m([int(input()) for i in range(n)]))

Python: def maxsum(A):
    smax = A[0]
    ssum = max(A[0], 0)
    for a in A[1:]:
        ssum += a
        smax = max(ssum, smax)
        ssum = max(ssum, 0)
    return smax

while True:
    n = int(input())
    if not n:
        break

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

    print(maxsum(A))

Python: # Aizu Problem 0022: Maximum Sum Sequence
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def max_sum_subsequence(seq):
    maxsofar = 0
    maxendinghere = 0
    for s in seq:
        # invariant: maxendinghere and maxsofar are accurate
        # are accurate up to s
        maxendinghere = max(maxendinghere + s, 0)
        maxsofar = max(maxsofar, maxendinghere)
    return maxsofar

while True:
    N = int(input())
    if N == 0:
        break
    seq = [int(input()) for _ in range(N)]
    print(max_sum_subsequence(seq))

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: n = int(input())
while n > 0:
    q = 0
    m = 0
    a = -100000
    for j in range(n):
        i = int(input())
        if i <= 0:
            a = max(a,i)
        if q == 0:
            if i <= 0:
                continue
            else:
                q = i
        else:
            q += i
            if q <= 0:
                q = 0
            else:
                m = max(m,q)
    print(m if m > 0 else a)
    n = int(input())

Python: while True:
  n = int(input())
  if n == 0:
    break
  acc = int(input())
  min_n = min(0, acc)
  max_n = acc
  ans = acc
  for _ in range(n - 1):
    acc += int(input())
    max_n = max(max_n, acc)
    ans = max(ans, max_n - min_n)
    min_n = min(min_n, acc)
  print(ans)

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: 
def partial_max(L):
    n=len(L)
    max=-100000000000
    max_i=0
    for i in range(n):
       if max < sum(L[:i+1]):
           max=sum(L[:i+1])
           max_i=i
    max = -100000000000
    max_j=0
    for j in range(n):
       if max < sum(L[j:]):
           max=sum(L[j:])
           max_j=j

    if max_i >= max_j:
        return sum(L[max_j:max_i+1])
    elif sum(L[max_j:])>sum(L[:max_i+1]):
        return sum(L[max_j:])
    else:
        return sum(L[:max_i+1])
n=int(input())
A=[]
while n!=0:
    A.append([int(input()) for i in range(n)])
    n=int(input())
for i in range(len(A)):
    print(partial_max(A[i]))

Python: INF = 10 ** 20
while True:
  n = int(input())
  if not n:
    break
  cum_sum = [0]
  acc = 0
  for i in range(n):
    acc += int(input())
    cum_sum.append(acc)
  ans = -INF
  for i in range(n):
    ans = max(ans, max(cum_sum[i + 1:]) - cum_sum[i])
  print(ans)

Python: while True:
    N=int(input())
    if N==0:
        break
    else:
        a=[]
        max=0
        for i in range(N):
            a.append(int(input()))
        for i in range(N):
            for j in range(N+1):
                    if sum(a[i:j])>=max:
                        max=sum(a[i:j])

        print(max)