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: n=int(input())
while(n!=0):
    index=0
    list=[]
    sum=0
    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: import math

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

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 b[len(b)-1] > 0 and a[i] > 0:
            b[len(b)-1] = b[len(b)-1] + a[i]
        else:
            b.append(a[i])

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

Python: while True:
    n=int(input())
    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
    dp = [-1e6]
    for i in range(n):
        a = int(input())
        dp.append(max(dp[i] + a, a))
    print(max(dp))

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]
            if tmp > sumMax:
                sumMax = tmp
    print(sumMax)

Python: # -*- coding: utf-8 -*-

import sys
import os

while True:
    s = input().strip()
    if s == '0':
        break

    N = int(s)
    A = []
    for i in range(N):
        v = int(input())
        A.append(v)

    max_value = 0
    for start_i in range(N):
        for end_i in range(start_i + 1, N):
            sum_value = sum(A[start_i:end_i+1])
            if sum_value > max_value:
                max_value = sum_value
    print(max_value)

Python: n=int(input())
while(n!=0):
    index=0
    list=[]
    sum=0
    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:
    num = int(input())
    if not num: break
    result = 0
    for _ in range(num):
        new = int(input())
        result = max(new, result, result+new)
    print(result)

Python: import sys
while True:
    n=int(input())
    if n==0:
        sys.exit()

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

    maximum=0
    for i in range(n+1):
        for j in range(i):
            maximum=max(maximum,a[i]-a[j])


    if maximum==0:
        b=a.copy()
        b.pop(0)
        maximum=max(b)

    print(maximum)

Python: while True:
    num = int(input())
    if not num: break
    result, tmp = 0, 0
    for _ in range(num):
        new = int(input())
        tmp = max(new, new+tmp)
        result = max(tmp, result)
    print(result)

Python: import sys

n = int(input())
while n != 0:
    max_seq = []
    max_val = int(input())
    for i in range(n-1):
        num = int(input())
        if num >= 0 and max_val >= 0:
            max_val += num
        else:
            if max_val >= 0:
                max_seq.append(max_val)
            if max_val >= 0 and max_val+num >= 0:
                max_val += num
            elif max_val >= 0 and max_val+num < 0:
                max_val = num
            elif max_val < 0 and max_val < num:
                max_val = num
    max_seq.append(max_val)
    print(max(max_seq))
    n = int(input())

Python: import sys
while True:
    n=int(input())
    if n==0:
        sys.exit()

    sum_list=[0]
    for i in range(n):
        sum_list.append(sum_list[-1]+int(input()))

    if max(sum_list)==0:
        sum_list.pop(0)
        print(max(sum_list))
    maximum=0
    for i in range(n):
        for j in range(i,n+1):
            maximum=max(sum_list[j]-sum_list[i],maximum)

    print(maximum)

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]==0:
            continue
        elif 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: import sys

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

    for i in range(len(a)+1):
        s.append(sum(a[0:i]))

    for i in range(len(a)+1):
        for j in range(1, len(a)+1):
            if (s[j] - s[i-1]) > sumMax:
                sumMax = s[j] - s[i-1]

    print(sumMax)

Python: while True:
    n = int(input())
    if not n:
        break
    
    A = []
    for i in range(n):
        a = int(input())
        A.append(a)

    smax = A[0]
    ssum = A[0]
    for a in A[1:]:
        if a + ssum > smax:
            smax = a + ssum
        ssum = max(ssum+a, 0)    
        
    print(smax)

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
  seq = []
  for _ in range(n):
    seq.append(int(input()))
  p_sum = -2000000
  for i in range(n):
    t_sum = 0
    for j in range(i,n):
      t_sum += seq[j]
      if t_sum > p_sum:
        p_sum = t_sum
  print(p_sum)