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: import math

def sign(x):
    if x >= 0:
        return True
    else:
        return False

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()))
    b = []
    b.append(a[0])
    for i in range(1,len(a)):
        if sign(b[len(b)-1]) == sign(a[i]):
            b[len(b)-1] = b[len(b)-1] + a[i]
        else:
            b.append(a[i])

    ans = b[0]
    for i in range(len(b)):
        for j in range(i,len(b)):
            ans = max(wa(b,i,j),ans)
    print(ans)
    n = int(input())

Python: n=int(input())
while(n!=0):
    index=0
    list=[]
    sum=0
    max=0
    for i in range(n):
        list.append(int(input()))

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

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

    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: def solve0(v):
    w = []
    l = len(v)
    ans = max([sum(v[i:j+1]) for i in range(l) for j in range(i,l)])
    return(ans)

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)
    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: #!/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())
    sumlist=[]
    sum=0
    max=-100000
    if n==0:
        break
    for i in range(n):
         sumlist.append(int(input()))
    for i in range(n):
        sum=0
        for j in range(0,n-i):
            sum=sumlist[i+j]+sum
            if max<sum:
                max=sum

    print(max)

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 maxsofar

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

Python: while True:
  n = int(input())
  if n == 0:
    break
  a = 0
  max_c = -200000
  while n > 0:
    i = int(input())
    a += i
    if max_c < a:
      max_c = a
    if a <= 0:
      a = 0
    n -= 1
  print(max_c)

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

    tup = tuple(int(stdin.readline()) for _ in xrange(n))
    L = [tup[0]]
    for i in tup[1:]:
        if 0 > i and 0 > L[-1]:
            L[-1] += i
        elif 0 <= i and 0 <= L[-1]:
            L[-1] += i
        else:
            L.append(i)

    m = 0
    for i in xrange(len(L)):
        for j in xrange(1 + i, len(L) + 1):
            t = sum(L[i:j])
            if t > m:
                m = t
    print(m)

Python: while True:
    n = int(input())
    if n == 0:
        break
    max_ = -1000000
    a = [int(input()) for x in range(n)]
    for i in range(n - 1):
        m = a[i]
        for j in range(i + 1, n):
            m += a[j]
            if m > max_:
                max_ = m
    print(max_)

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 = int(input())
    a = [int(input()) for _ in range(n)]

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

    print(max(dp))

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

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

    m = 0
    for i in range(0, len(a)):
        for j in range(i + 1, len(a) + 1):
            m = max(m, sum(a[i:j]))

    print(m)

Python: from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def grouping(nums):
    it = iter(nums)
    L = [next(nums)]
    minus = L[0] < 0
    for n in it:
        if (n < 0 and minus) or (n >= 0 and not minus):
            L[-1] += n
        else:
            L.append(n)
            minus = not minus
    return L

def collect(nl):
    result = 0
    while len(nl) > 1:
        nl = grouping(nl[i] + nl[i+1] for i in xrange(0, len(nl), 2))
        if nl[-1] <= 0:
            nl.pop()
            if not len(nl):
                break
        if nl[0] >= 0:
            result += nl[0]
            nl.pop(0)
    return result

while True:
    n = int(stdin.readline())
    if not n:
        break

    L = grouping(int(stdin.readline()) for _ in xrange(n))
    if L[0] <= 0:
        L.pop(0)
    if L[-1] <= 0:
        L.pop()

    val = max(L)
    idx = L.index(val)

    val += collect(list(reversed(L[:idx])))
    val += collect(L[idx+1:])
    print(val)