Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

Python: import sys
while True:
    n=int(input())
    if n==0:
        sys.exit()

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

    maximum=0
    for i in range(n+1):
        for j in range(i):
            maximum=max(maximum,a[i]-a[j])


    if maximum==0:
        b=a.copy()
        b.pop(0)
        maximum=max(b)

    print(maximum)

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

Python: import sys

n = int(input())
while n != 0:
    max_seq = []
    max_val = int(input())
    for i in range(n-1):
        num = int(input())
        if num >= 0 and max_val >= 0:
            max_val += num
        else:
            if max_val >= 0:
                max_seq.append(max_val)
            if max_val >= 0 and max_val+num >= 0:
                max_val += num
            elif max_val >= 0 and max_val+num < 0:
                max_val = num
            elif max_val < 0 and max_val < num:
                max_val = num
    max_seq.append(max_val)
    print(max(max_seq))
    n = int(input())

Python: import sys
while True:
    n=int(input())
    if n==0:
        sys.exit()

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

    if max(sum_list)==0:
        sum_list.pop(0)
        print(max(sum_list))
    maximum=0
    for i in range(n):
        for j in range(i,n+1):
            maximum=max(sum_list[j]-sum_list[i],maximum)

    print(maximum)

Python: def solve0(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))

def sign(x):
    if x >= 0:
        s=+1
    else:
        s=-1
    return(s)

def solve(v):
    w = []
    sig=sign(v[0])
    x = v[0]    
    for i in range(1,len(v)):
        if v[i]==0:
            continue
        elif v[i] * sig > 0:
            x += v[i]
        else:
            w.append(x)
            sig=sign(v[i])
            x=v[i]
    w.append(x)
#    print(w)
    return(solve0(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

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

    for i in range(len(a)+1):
        s.append(sum(a[0:i]))

    for i in range(len(a)+1):
        for j in range(1, len(a)+1):
            if (s[j] - s[i-1]) > sumMax:
                sumMax = s[j] - s[i-1]

    print(sumMax)

Python: while True:
    n = int(input())
    if not n:
        break
    
    A = []
    for i in range(n):
        a = int(input())
        A.append(a)

    smax = A[0]
    ssum = A[0]
    for a in A[1:]:
        if a + ssum > smax:
            smax = a + ssum
        ssum = max(ssum+a, 0)    
        
    print(smax)

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

Python: while True:
  n = int(input())
  if n == 0:
    break
  seq = []
  for _ in range(n):
    seq.append(int(input()))
  p_sum = -2000000
  for i in range(n):
    t_sum = 0
    for j in range(i,n):
      t_sum += seq[j]
      if t_sum > p_sum:
        p_sum = t_sum
  print(p_sum)

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

Python: a = []
b = []


def searchs(i, n, m):
    b.clear()
    for k in range(i+1, n+1):
        b.append(sum(a[i:k]))
    # print(b)
    if m < max(b):
        m = max(b)
    if i+1 < n:
        m = searchs(i+1, n, m)
    return m


while True:
    user = input()
    n = int(user)
    if n == 0:
        break
    a.clear()
    for i in range(n):
        a.append(int(input()))
    # print(a)
    print(searchs(0, n, 0))

Python: while True:
    n = int(input())
    if not n:
        break
    l = [int(input()) for j in range(n)]
    s = [l[0]]
    for k, v in enumerate(l[1:]):
        s.append(max(v, v + s[k]))
    print(max(s))

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

Python: import sys

n = int(sys.stdin.readline())
while n:
    l = list()
    for _ in range(n):
        l.append(int(input()))

    maxs = 0
    for i in range(n):
        for j in range(i,n):
            s = 0
            for k in range(i,j+1):
                s += l[k]
            maxs = max(maxs,s)
    n = int(sys.stdin.readline())
    print(maxs)

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

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

    dp = []
    dp.append(a[0])
    for i in range(1,len(a)):
        dp.append(max(dp[i-1] + a[i], a[i]))

    print(max(dp))

Python: # -*- coding: utf-8 -*-

import sys
import os

def max_seq(A):
    acc = max(0, A[0])
    ans = max(0, A[0])

    for i in range(1, len(A)):
        v = acc + A[i]
        if v < 0:
            # ???????????§???????????????acc??????????¶???????????????????
            ans = max(ans, acc)
            # ????????????
            acc = max(0, A[i])
        else:
            acc = v
            ans = max(ans, acc)
    return ans

while True:
    s = input().strip()
    if s == '0':
        break

    N = int(s)
    A = []
    for i in range(N):
        v = int(input())
        A.append(v)

    print(max_seq(A))

Python: while(1):
    N = int(input())
    if N==0: break
    sums = []
    s = 0
    for i in range(N):
        s += int(input())
        if s<0: s=0
        sums.append(s)
    print(max(sums))

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 max(maxsofar, max(seq))

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