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

Python: 

while True:
    num = int(input())

    if num == 0: 
        break
    
    list = []
    for i in range(num):
        list.append(int(input()))

    for i in range(1, num):
        list[i] = max(list[i - 1] + list[i], list[i])

    print(max(list))

Python: while 1:
    m=0
    l=[]
    n=int(input())
    if not n: break
    for i in range(n):
        j=int(input())
        if i==0:
            m+=j
        elif s*j<0:
            l.extend([m])
            m=j
        else:
            m+=j
        s=j
    l.extend([m])
    b=len(l)
    print(max([sum(l[i:j]) for j in range(1,b+1) for i in range(j)]))

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

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

Python: n = int(input())
while n > 0:
    s = []
    m = 0
    for i in range(n):
        m += int(input())
        s.append(m)
    print(max(s))
    n = int(input())

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

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

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])
    if d[0] < 0:
        d.pop(0)
    if d == []:
        print(max(a))
    if len(d) <= 2:
        print(max(d))
    else:
        maxd = max(d)
        for i in range(0, len(d), 2):
            for j in range(i + 1, len(d) + 1, 2):
                maxd = max(maxd, sum(d[i:j]))
        print(maxd)

Python: n=int(input())
while(n!=0):
    index=0
    list=[]
    sum=0
    max=0
    break_flag=False
    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

    if index==len(list):
        print(max)
        break_flag=True

    if not break_flag:
        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())