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: #!/usr/bin/env python
# -*- coding: utf-8 -*-

n = []
a = []

i = 0
while True:
    n.append(int(input()))
    if n[i] == 0:
        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: a = []
b = []


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

Python: import sys

n = 1

while 1:
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for _ in range(n)]
    print(sum(a))

Python: class Node:
    prev = next = None

    def __init__(self, value):
        self.value = value

    def get_nxnx(self):
        next_n = self.next
        if not next_n: return None, None
        return next_n, next_n.next

    def get_prpr(self):
        prev_n = self.prev
        if not prev_n: return None, None
        return prev_n, prev_n.prev

    def combine(self):
        next_n, nxnx_n = self.get_nxnx()
        if not next_n or not nxnx_n: return False

        if self.value > abs(next_n.value) < nxnx_n.value:
            self.value += next_n.value + nxnx_n.value
            self.next = nxnx_n.next
            _, prpr = self.get_prpr()
            if prpr:
                prpr.combine()
            return True
        return False

    def iter(self):
        a = self
        while a:
            yield a.value
            a = a.next


while True:
    n = int(input())
    if not n:
        break
    a0 = a = Node(int(input()))
    n -= 1
    while n:
        an = int(input())
        if an * a.value < 0:
            at = Node(an)
            at.prev = a
            a.next = at
            a = at
        else:
            a.value += an
        n -= 1
    if a0.value < 0:
        a0 = a0.next
    a = a0
    while a:
        while a.combine():
            pass
        _, a = a.get_nxnx()
    print(max(v for v in a0.iter()))

Python: while 1:
    n=int(input())
    if n==0:break
    nlist=[]
    nans=-100001
    for i in range(n):
        nlist.append(int(input()))
    nkeep=0
    for i in nlist:
        if i>0 and nkeep>=0:
            nkeep+=i
        elif nkeep<0:
            nkeep=i
        if nans<nkeep:nans=nkeep
    if max(nlist)<0:nans=max(nlist)
    print(nans)

Python: while 1:
    n=int(input())
    if n==0:break
    nlist=[]
    nans=-100001
    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]
            if nans<nn:nans=nn
    print(nans)

Python: while True:
    n = int(input())
    if not n:
        break
    a = [int(input()) for _ in range(n)]
    for i in range(1, n):
        if a[i - 1] > 0:
            a[i] += a[i - 1]
    print(max(a))

Python: while True:
    n = int(input())
    if n == 0:
        break
    seq = [int(input()) for _ in range(n) ]
    for i in range(1, n):
        seq[i] = max(seq[i], seq[i - 1] + seq[i])
    print(max(seq))

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

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):
        sum += list[index]
        index += 1

    max=sum
    sum=0

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

Python: while 1:
    n=int(input())
    if not n:break
    l=[int(input()) for _ in range(n)]
    print(max(sum(l[j:i]) for i in range(len(l)+1) for j in range(i)))

Python: def solve0(v):
    w = []
    for i in range(len(v)):
        for j in range(len(v[i:])):
            w.append(sum(v[i:(j+1)]))
    return(max(w))

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