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)
	}
}

C++: #include <bits/stdc++.h>

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    int N;

    while(cin >> N, N)
    {   
        vector<ll> a(N);
        rep(i, N) cin >> a[i];        

        vector<ll> dp(N, 0);

        dp[0] = a[0];

        rep(i, N - 1)
            dp[i + 1] = max(dp[i] + a[i + 1], a[i + 1]);

        ll ans = -llINF;

        rep(i, N) ans = max(dp[i], ans);

        cout << ans << endl;
        
    }

    return 0;
}

C++: #include <stdio.h>

int main()
{
        int n, i, j, k;
        double a[5000], sum, max;

        while (scanf("%d", &n) && n != 0) {
                for (i = 0; i < n; i++)
                       scanf("%d", &a[i]);

                max = 0;
                for (j = 0; j < n; j++) {
                        sum = 0;
                        for (i = j; i < n; i++) {
                                sum += a[i];
                                if (sum > max) {
                                        max = sum;
                                }
                        }
                }
                printf("%d\n", max);
        }
        return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main_(void)
{
	int n, a[5001];
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int goukei = 0, ryuta = -10000000;
	for (int i = 1; i <= n; i++)
	{
		goukei = 0;
		for (int j = 1; j <= n; j++)
		{
			goukei = goukei+a[j];
			ryuta = max(goukei, ryuta);
		}
	}
	cout << ryuta << endl;
	return 0;
}

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

int main() {
	int n,a[5000],i,j,max,sum;
	
	while(cin>>n,n){
		
		for(i=0;i<n;++i)cin>>a[i];
		
		max=-100000;
		
		for(i=0;i<n;++i){
			sum=0;
			for(j=i;j<n;++j){
				sum+=a[j];
				if(sum>max)max=sum;
			}
		}
		
		cout << max << endl;
	}
}

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

vector<int> num;

int main(void){
  while(true){
    int maximum = 0, n;
    cin >> n;
    if(!n)  break;
    num.clear();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < num.size(); i++){
      int sum = num[i];
      maximum = num[i];
      for(int j = i + 1; j < num.size(); j++){
        sum += num[j];
        if(sum > maximum) maximum = sum;
      }
      if(sum > maximum) maximum = sum;
    }
    cout << maximum << endl;
  }
  return 0;
}

C++: #include<stdio.h>

int N[5001]={};
int main(){

int n,x;

while(1){
scanf("%d",&n);if(n==0)break;


for(int i=0;i<n;i++)
scanf("%d",&N[i]);
int t=0,s=0;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
s+=N[j];if(t<s)t=s;
}
s=0;
}
printf("%d\n",t);
}
return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
using namespace std;

int main(void){
	int i,j,k,n,a[5000],ans;
	while(1){
	cin >> n;
	if(n == 0) break;
	ans = 0;
	a[0] = 0;
	k = 0;
	for(int t=0;t<n;t++){
		int x = 0;
		cin >> x;
		if(a[k] == 0) a[k] += x;
		else if(a[k] > 0 && x > 0 || a[k] < 0 && x < 0) a[k] += x;
		else a[++k] = x;
	}
	k++;
	if(a[0] < 0){
		for(i=0;i<k-1;i++) a[i] = a[i+1];
		k--;
	}

	for(i=1;i<k-1;i++){
		if(a[i] < 0 && a[i] + a[i+1] > 0){
			a[i-1] += a[i] + a[i+1];
			for(j=i;j<k-2;j++) a[j] = a[j+2];
			k -= 2;
		}
	}

	for(i=0;i<k;i++) ans = max(ans,a[i]);

	cout << ans << endl;
}
	return 0;
}

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

typedef long long ll;
const ll INF = 10000000000;

int main()
{
	ll t, n;
	while( 1 )
	{
		scanf("%lld", &t);
		if(t == 0) break;

		ll c_max = -INF;
		ll c_min = 0;
		ll c_sum = 0;
		for(int i=0; i<t; i++)
		{
			scanf("%lld", &n);
			c_sum += n;
			if(c_min > c_sum) c_min = c_sum;
			if(c_max < c_sum - c_min) c_max = c_sum - c_min;
		}
		printf("%lld\n", c_max);
	}
}

C++: // AOJ 0022
#include <cstdio>
#include <cstring>

int main(void)
{
    int n;
    int num[5001];
    int sum;
    int max;
    
    while (scanf("%d", &n)){
        if (n == 0) break;
        
        memset(num, 0, 5001);
        for (int i = 0; i < n; i++){
            scanf("%d", &num[i]);
        }
        max = num[0];
        
        for (int i = 0; i < n; i++){
            sum = 0;
            for (int j = i; j < n; j++){
                sum += num[j];
                if (max < sum) max = sum;
            }
        }
        
        printf("%d\n", max);
    }
}

C++: #include <stdio.h>
int main()
{
	int n,a[5000];
	while(scanf("%d",&n)!=EOF){
		int max=-10001;
		if(n==0)
			break;
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				if(max<sum)
					max=sum;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

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

int main()
{
	int n=1, count = 0;
	int a[10000],ans[10000];
	while (n != 0) {
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = 0;
		for (int ai = 0; ai < n - 1; ai++) {
			for (int bi = n; bi > ai; bi--) {
				sum = 0;
				for (int k = ai; k < bi; k++) {
					sum = sum + a[k];
				}
				if (sum > max) {
					max = sum;
				}
			}
		}
		ans[count] = max;
		count++;
	}
	for (int ci = 0; ci < count-1; ci++) {
		cout << ans[ci] << endl;
	}
}

C++: #include <iostream>

#define SIZE 5001

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}

		int list[SIZE], max = -114514;
		list[0] = 0;
		for (int i = 0; i < n; i++) {
			cin >> list[i + 1];

			if (list[i + 1] > max) {
				max = list[i + 1];
			}
			list[i + 1] += list[i];
		}

		for (int i = 2; i <= n; i++) {
			for (int j = i; j <= n; j++) {
				if (list[j] - list[j - i] > max) {
					max = list[j] - list[j - i];
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a[5000],i,j,sum=0,max[5000]={-10001},c=0,n;
	
	while(1){
		scanf("%d",&n);
		if( n == 0)
			break;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				sum = sum + a[j];
				if(max[c] < sum)
					max[c] = sum;
			}
			sum = 0;
		}
		c++;
	}
	for(i=0;i<c;i++){
		printf("%d\n",max[i]);
	}
	return 0;
}

C++: #include<stdio.h>

int main()
{
	int n;
	for(;;)
	{
		scanf("%d",&n);
		if(n==0){return 0;}
		
		if( n >= 1 && n <= 5000){
		int a[5000]={0},max=0;
		for(int x=0;x<n;x++)
		{
			scanf("%d",&a[x]);

			for(int y=0;y<=x;y++)
			{
				if(y!=x)
				{
					a[y]+=a[x];
				}
				if(max<a[y])
				{
					max=a[y];
				}
			}
		}
		printf("%d\n",max);
		}
	}
}