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

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

Python: n=int(input())
while(n!=0):
    index=0
    list=[]
    sum=-1
    max=0
    for i in range(n):
        list.append(int(input()))
    max=list[0]
    while (index < len(list) and list[index] < 0):
        if max<list[index]: max = list[index]
        index += 1

    while (index < len(list) and list[index] >= 0):
        sum += list[index]
        index += 1

    if sum>=0: max=sum

    while(index<len(list)):
        plus_sum = 0
        minus_sum = 0

        while (index < len(list) and list[index] < 0):
            minus_sum += list[index]
            index += 1

        while (index < len(list) and list[index] >= 0):
            plus_sum += list[index]
            index += 1

        if abs(minus_sum)<plus_sum:
            sum+=(minus_sum+plus_sum)
            if max<sum: max=sum
        else:
            sum=plus_sum
            if max<sum: max=sum
    print(max)
    n=int(input())

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: from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from sys import stdin

while True:
    n = int(stdin.readline())
    if not n:
        break
    m = 0
    tup = tuple(int(stdin.readline()) for _ in xrange(n))
    for i in xrange(len(tup)):
        for j in xrange(1 + i, len(tup) + 1):
            t = sum(tup[i:j])
            if t > m:
                m = t
    print(m)

Python: while 1:
    n=input()
    if n==0:break
    a=[int(raw_input()) for _ in xrange(n)]
    wa=[0]*(n+1)
    max_a=-1000000
    for i in xrange(n):
        wa[i+1]=a[i]+wa[i]
    for i in xrange(n):
        for j in xrange(i+1,n+1):
            if max_a<wa[j]-wa[i]:
                max_a=wa[j]-wa[i]
    print(max_a)

Python: while True:
    n = int(input())
    sumlist=[]
    max=-100000
    if n==0:
        break
    for i in range(n):
         sumlist.append(int(input()))
    sum=0
    buf=0
    for i in range(n):
        buf = sumlist[i]+buf
        if buf + sum > max:
            sum = sum+buf
            max=sum
            buf = 0
        if sumlist[i] > max:
            sum = sumlist[i]
            max = sumlist[i]
            buf = 0
    print(max)

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

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