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: 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)

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])
    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
  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)

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

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

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

    sum = [0 for i in range(n + 1)]
    for i in range(n):
        sum[i + 1] = sum[i] + a[i]

    ans = -(10**18)
    for i in range(n + 1):
        for j in range(1, i + 1):
            ans = max(ans, sum[i] - sum[i - j])

    print(ans)

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

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
    a = [int(input()) for _ in range(n)]
    ans = a[0]
    for i in range(n):
        tmp = 0
        for j in range(i, n):
            tmp += a[j]
            ans = max(ans, tmp)
    print(ans)

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

import sys
import os
import math

N = int(input())

for i in range(N):
    ax, ay, ar, bx, by, br = map(float, input().split())

    between_center = math.hypot(ax - bx, ay - by)

    # ????????£????????????
    if between_center > ar + br:
        print(0)

    # ????????????????????¨
    else:
        # B in A
        if ar > between_center + br:
            print(2)

        # A in B
        elif br > between_center + ar:
            print(-2)

        else:
            print(1)

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

import sys
import os
import math


N = int(input())

for i in range(N):
    ax, ay, ar, bx, by, br = map(float, input().split())

    between_center = math.hypot(ax - bx, ay - by)

    # ????????£????????????
    if between_center > ar + br:
        print(0)

    # ????????????????????¨
    else:
        # B in A
        if ar > between_center + br:
            print(2)

        # A in B
        elif br > between_center + ar:
            print(-2)

        else:
            print(1)

Python: while 1:
    n=int(input())
    if n==0:break
    nlist=[]
    nans=[]
    for i in range(n):
        nlist.append(int(input()))
        for j in range(i+1):
            nn=0
            for k in range(j,i+1):
                nn+=nlist[k]
            nans.append(nn)
    print(max(nans))

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

    a = (int(raw_input()) for _ in xrange(n))
    b = []
    c = 0
    for ai in a:
        if ai == 0:
            continue
        if (c > 0 and ai < 0) or (c < 0 and ai > 0):
            b.append(c)
            c = 0
        c += ai

    if c != 0:
        b.append(c)

    l = len(b)
    i = 0 if b[0] > 0 else 1
    s = b[i]
    ans = s

    j = i + 2
    while j < l:
        s += b[j - 1] + b[j]
        while i < j:
            ns = s - b[i] - b[i + 1]
            if ns < s:
                break
            s = ns
            i += 2
        ans = max(s, ans)
        j += 2

    print(ans)

Python: while True:
    N=int(input())
    if N==0:
        break
    num=0
    res=-11111111
    for i in range(N):
        a=int(input())
        num=max(num+a,a)
        res=max(num,res)

    print(num)