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:
    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 sumlist[i] > max and (buf <= 0):
            sum = 0
            max = sumlist[i]
            buf = 0

        elif buf + sum > max:
            sum = sum+buf
            max=sum
            buf = 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(1, n):
        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
    s=0
    for _ in range(n):
        i = int(input())
        if i > 0: s+=i

    print(s)

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

Python: 

def solve(a_list):
    if len(list(filter(lambda x: x >= 0, a_list))) == 0:
        return max(a_list)

    dp = [0] * len(a_list)
    dp[0] = max(0, a_list[0])
    for i in range(1, len(dp)):
        dp[i] = max(0, a_list[i] + dp[i - 1])

    return max(dp)


def main():
    while True:
        n = int(input())
        if n == 0:
            break
        a_list = [int(input()) for _ in range(n)]
        print(solve(a_list))


if __name__ == '__main__':
    main()

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 len(d) <= 2:
        print(max(max(d), max(a)))
    else:
        if d[0] < 0:
            d.pop(0)
        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: while True:
    n = int(input())
    if n==0 : break

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

    maxi = 0
    for i in range(1,1+n):
        for j in range(n-i+1):
            if maxi < sum(a[j:j+i]):
                maxi = sum(a[j:j+i])

    print(maxi)

Python: import sys
import math as mas

while True:
	n=int(input())
	if n==0:break
	a=[int(input()) for i in range(n)]
	ma=-100010
	for i in range(n):
		sum=0
		for j in range(i,n):
			sum+=a[j]
			ma=max(ma,sum)
	print(ma)

#for i in sys.stdin:
#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))

Python: while True:
    n = int(input())
    if n == 0:
        break
    a = []
    for _ in range(n):
        a.append(int(input()))
    print(max(max(sum(a[j:j + i + 1]) for j in range(n - i)) for i in range(n)))

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(a[i], maxcont + a[i])
        maxp = max(maxp, maxcont)

    print(maxp)

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

Python: from sys import stdin

def getMax(array):
    mx = mx2 = array[0]
    for i in array[1:]:
        mx2 = max(i, mx2 + i)
        mx = max(mx, mx2)
    return mx

for line in stdin:
    n = int(line)
    if n == 0:
        break
    array = []
    for line in stdin:
        line = int(line)
        array.append(line)
        if len(array) == n:
            break
    print(getMax(array))

Python: if __name__ == '__main__':
    while True:
        # ??????????????\???
        loop = int(input())
        if loop == 0:
            break
        data = [int(input()) for _ in range(loop)]

        # ???????????????
        max_total = 0  # ??£?¶?????????°???????????§????¨????
        total = 0
        for d in data:
            if d > 0:  # ??°??????+??§????????°?????±????°????
                total += d  # ????¨?????¶???????????¨?????????´??°????????????????¢????????????????
                if total > max_total:
                    max_total = total
            else:  # ??°??????-?????´?????????????????§????????£???????????????????????§??????????????????
                if total > abs(d):  # ???????????§??????????????????????????§????????°???total???????????????????¶??¶???????
                    total += d
                    # ???????????????????????????????????§???max_total?????´??°??????????????§?????????
                else:
                    total = 0  # ???????????????????????§??????????????????????????§??????????????§????¨??????????????????????????¬??????????????????????????????????

        # ???????????¨???
        print(max_total)

C++: #include<iostream>
#include<climits>
using namespace std;

int main(){
	int n,a[5001];
	int ans;
	a[0]=0;
	while(cin>>n&&n){
		ans = INT_MIN;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			a[i] += a[i-1];
		}
		for(int i=1;i<=n;i++){
			for(int j=i;j<=n;j++){
				ans = max(ans,a[j]-a[i-1]);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,d[5000];
  int sum,max;
  while(cin>>n){
    if(n==0)break;
    max=-100001;
    for(int i=0;i<n;i++){
      cin>>d[i];
    }
    for(int i=0;i<n;i++){
      sum=0;
      for(int j=i;j<n;j++){
	sum+=d[j];
	if(sum>max){
	  max=sum;
	}
      }
    }
    cout<<max<<endl;
  }
  return 0;
}

C++: // 0022.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(ll a=0;a<t;a++) 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	while (cin >> n) {
		if (n == 0) { break; }
		ll dp[5001]; ll a[5001];
		ll ans = -9000000000;
		roop(i, n) {
			cin >> a[i];
			
			if (i > 0) {
				dp[i] = max(dp[i - 1] + a[i], a[i]);
			}
			else {
				dp[i] = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			ans = max(dp[i],ans);
		}
		cout << ans << endl;
	}
	return 0;
}