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 True:
 try:
  n=int(input())
  a=[int(input()) for i in range(n)]
  print(max(a))
 except EOFError:
  break

Python: while True:
    n = int(input())
    m = -1000000 
    if not n :
        break
    dataset = [int(input()) for _ in range(n)]
    for i in range(n):
        for j in range(i, n + 1):
            if dataset[i:j] != []:
                s = sum(dataset[i:j])
                if m < s:
                    m = s
    print(m)

Python: def wa(a,x,y):
    S = 0
    for i in range(x,y+1):
        S = S + a[i]
    return S

n = int(input())
while n != 0:
    a = []
    for i in range(n):
        a.append(int(input()))
    ans = a[0]
    for i in range(n):
        for j in range(i+1,n):
            ans = max(wa(a,i,j),ans)
    print(ans)
    n = int(input())

Python: import itertools

while True:
    n = int(input())
    if n == 0:
        break
    else:
        a = [int(input()) for i in range(n)]
        a = list(itertools.accumulate(a))
        a.insert(0, 0)
        ans = a[1]
        for j in range(n + 1):
            for k in range(n + 1):
                ans = max(ans, a[k] - a[j])
        print(ans)

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 = -10001
    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:
    n = int(input())
    if n==0 : break

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

    maxp = 0
    maxcont = 0

    for i in range(n):
        maxcont = max(0, maxcont + a[i])
        maxp = max(maxp, maxcont)

    print(maxp)

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

n = []
a = []

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

count = 0
for i in range(0,len(n)):
    sumMax = 0
    for j in range(count,count + n[i]):
        tmp = 0
        for k in range(j,count + n[i]):
            tmp += a[k]
            sumMax = max(sumMax,tmp)
    count += n[i]
    print(sumMax)

Python: #!/usr/bin/python


def main():
    while True:
        try:
            num_data = int(raw_input())
            if num_data == 0:
                break

            data = []
            for i in xrange(num_data):
                data.append(int(raw_input()))

            max = max_sum_sequence(data)
            print(max)
        except:
            break


def max_sum_sequence(data):
    sum = [0]
    n = len(data)

    for i in xrange(n):
        sum.append(sum[-1] + data[i])

    mx = - (1 << 30)
    for i in xrange(n):
        for j in xrange(i + 1, n + 1):
            mx = max(mx, sum[j] - sum[i])

    return mx


main()

Python: a = []
b = []


def searchs(i, n, m):
    if b != []:
        b.clear()
    if a != []:
        for k in range(i+1, n+1):
            b.append(sum(a[i:k]))
    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
    if a != []:
        a.clear()
    for i in range(n):
        a.append(int(input()))
    # print(a)
    print(searchs(0, n, 0))

Python: from collections import deque
while True:
    n = int(input())
    if n == 0:break
    a = [int(input()) for _ in range(n)]
    b = deque([0] * n)
    j = 0
    for i in range(n):
        if a[i] * b[j] >= 0:b[j] += a[i]
        else:j += 1;b[j] += a[i]
    if b[0] < 0:b.popleft()
    while b[-1] <= 0 and len(b) > 1:b.pop()
    m = len(b) // 2 + 1
    v = [[0] * m for _ in range(m)]
    v[0][0] = b[0]
    for i in range(1, m):
        v[0][i] = v[0][i - 1] + b[2 * i] + b[2 * i - 1]
    for i in range(1, m):
        for j in range(i, m):
            v[i][j] = v[i - 1][j] - b[2 * i - 2] - b[2 * i - 1]
    print(max([max(i) for i in v]))

Python: def solve(v):
    w = []
    sig=sign(v[0])
    x = v[0]    
    for i in range(1,len(v)):
        if 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: 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)
    print(d)
    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):
                print("{} {} {}".format(i, j, sum(d[i:j])))
                maxd = max(maxd, sum(d[i:j]))
        print(maxd)

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

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: #!/usr/bin/python


def main():
    while True:
        try:
            num_data = int(raw_input())
            if num_data == 0:
                break

            data = []
            for i in xrange(num_data):
                data.append(int(raw_input()))

            max = max_sum_sequence(data)
            print(max)
        except:
            break


def max_sum_sequence(data):
    max = 0
    num_data = len(data)
    for l in xrange(1, num_data + 1):
        # print ("testing at l = " + str(l) + "..")
        sum = max_at_length(data, l)
        if sum > max:
            max = sum

    return max


def max_at_length(data, length):
    max = 0
    num_data = len(data)

    sum = None
    old_head = 0

    #print "length = " + str(length)

    while True:
        if sum is None:
            sum = 0
            for i in xrange(0, length):
                sum += data[i]
            #print "initial = " + str(sum)
            max = sum

        else:
            if old_head + length < num_data:
                #print "sum = %d - %d + %d" % (sum, data[old_head], data[old_head + length])
                sum = sum - data[old_head] + data[old_head + length]
                #print "     = " + str(sum)
                if sum > max:
                    max = sum

                old_head += 1
            else:
                break

    return max

main()