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(1):
    N = int(input())
    if N==0: break
    sums = []
    nums = []
    s = 0
    for i in range(N):
        n = int(input())
        nums.append(n)
        s += n
        if s<0: s=0
        sums.append(s)
    if max(nums) >= 0:
        print(max(sums))
    else:
        print(max(nums))

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

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

    t = [int(input()) for i in range(n)]
    m = sum(t)
    while len(t) > 1:
        if t[0] < t[-1]:
            a = t.pop(0)
        else:
            a = t.pop(-1)
        if a < 0:
            m = max(sum(t), m)

    print(m)

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:]
	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())
    sumlist=[]
    sum=0
    max=-10000
    if n==0:
        break
    for i in range(n):
         sumlist.append(int(input()))
    for i in range(n):
        sum=0
        for j in range(0,n-i):
            sum=sumlist[i+j]+sum
            if max<sum:
                max=sum

    print(max)

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

Python: while 1:
    n=int(input())
    if n==0:break
    nlist=[]
    nans=-100001
    for i in range(n):
        nlist.append(int(input()))
    nkeep=0
    for i in nlist:
        if nkeep<0:
            nkeep=i
        else:
            nkeep+=i
        if nans<nkeep:nans=nkeep
    if max(nlist)<0:nans=max(nlist)
    print(nans)

Python: def solve(v):
    w = []
    for i in range(len(v)):
        for j in range(len(v[i:])):
            w.append(sum(v[i:(j+1)]))
    return(max(w))

if __name__ == "__main__":
    while True:
        n = int(input())
        if n == 0:
            break
        v = []    
        for i in range(n):
            v.append(int(input()))

        print(solve(v))

Python: import sys
readline = sys.stdin.readline
write = sys.stdout.write

def solve():
    N = int(readline())
    if N == 0:
        return False
    mi = su = 0
    ans = -10**9
    for i in range(N):
        a = int(readline())
        su += a
        ans = max(ans, su - mi)
        mi = min(su, mi)
    print(ans)
    return True
while solve():
    ...

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

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

Python: n=int(input())
while(n!=0):
    list=[]
    list.append(int(input()))
    for i in range(1,n):
        num=int(input())
        list.append(max(num,num+list[i-1]))
    print(max(list))
    n=int(input())

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

    ans = -1000000000
    a = [0]
    for i in range(n):
        a.append(int(input())) # a = [input() for i in range(n)]
        a[i+1] += a[i]
        
        for j in range(0,i+1):
            ans = max(ans, a[i+1]-a[j])

    print(ans)

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) - 1):
            if a[i] * a[i + 1] < 0:
                b.append(sum(a[:i + 1]))
                a[:i + 1] = []
                break
        else:
            b.append(sum(a))
            a = []
    for i in range(1, len(b)):
        if b[i - 1] > 0:
            b[i] += b[i - 1]
    print(max(b))

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

Python: def take(n, iterable):
    start, end = 0, n
    while True:
        chunk = iterable[start:end]
        if len(chunk) < n:
            raise StopIteration()
        yield chunk
        start += 1
        end += 1
while True:
    num = int(input())
    if not num: break
    data = [int(input()) for _ in range(num)]
    print(max((sum(chunk) for i in range(1,num+1) for chunk in take(i, data))))

Python: while True:
  n = int(input())
  if n == 0:
    break
  acc = int(input())
  min_n = acc
  max_n = 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, max_n)
  print(ans)

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

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):
                suma=sum(a[i:j+1])
                if ans<suma:
                    ans=suma
        print(ans)

Python: while 1:
 n=int(input())
 if n:
  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: import sys

s = ""
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
        else:
            if m < 0 and max < sum:
                max = sum
            sum += m
    if sum > max:
        s += str(sum) + "\n"
    else:
        s += str(max) + "\n"

print(s,end="")

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

    ans=-1e100
    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: break
    a, b = 0, -100000
    num = [int(input()) for _ in range(n)]
    for n in num:
        a = max(a+n, n)
        b = max(a, b)
    print(b)

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())
    min_n = min(min_n, acc)
    max_n = max(max_n, acc)
    ans = max(ans, max_n - min_n)
  print(ans)