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>
using namespace std;

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int n;
    while (cin >> n, n)
    {
        vector<long long int> data;
        data.push_back(0);
        rep(i, n)
        {
            long long int temp;
            cin >> temp;
            data.push_back(data[i] + temp);
        }
        long long int ans = INT_MAX*-1;
        rep(i, n + 1)
        {
            REP(j, i + 1, n + 1)
            {
                ans = max(ans, data[j] - data[i]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int item[1000];
int num = 0;

// ????????????????§???????MAX????¶?????????¨??´??°??????
int GetMax(){
  int max_sum = 0;
  for(int i = 0; i < num; i++){
    int sum = 0;
    for(int j = i; j < num; j++){
      sum += item[j];
      max_sum = max(max_sum, sum);
    }
  }
  return max_sum;
}
  
void GetItem(){
  cin >> num;
  for(int i = 0; i < num; i++){
    cin >> item[i];
  }
}

int main(){
  while(true){
    GetItem();
    if(num == 0) { break; }
    cout << GetMax() << endl;
  }
}

C++: #include<cstdio>

int main(){
	int n,max,sum,t;
	scanf("%d", &n);
	while(n){
		scanf("%d", &t);
		max = sum = t;
		for(int i = 1; i < n; i++){
			scanf("%d", &t);
			sum += t;
			if(sum > max){
				max = sum;
			}
			if(sum < 0){
				sum = 0;
			}
		}
		printf("%d\n", max);
		scanf("%d", &n);
	}
	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 <bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n;
        cin>>n;
        if(n==0){
            return 0;
        }
        vector<int> a(n);
        for(int i=0;0<n;i++){
            cin>>a.at(i);
        }
        vector<int> b(n+1);
        b.at(0)=0;
        for(int i=1;i<=n;i++){
            b.at(i)=b.at(i-1)+a.at(i-1);
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            for(int j=0;j<i;j++){
                ans=max(ans,b.at(i)-b.at(j));
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include<iostream>

using namespace std;

int main(){

int n;
int a[10000];
long long int ans = -1000000000;

while(true){

cin >> n;

if(n == 0) break;

for(int i = 0; i < n; i++){

cin >> a[i];

}

long long int sum;

for(int i = 0; i < n; i++){
sum = 0;
for(int j = i; j < n; j++){
sum += a[j];
if(sum > ans){
ans = sum;
}
}
}

cout << ans << endl;

}

return 0;

}

C++: #include <iostream>
typedef long long ll;
using namespace std;
 
int main(){
    int n,a[5001];
    ll 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>
#include<cstring>
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
    int n;
    while(cin >> n &&n)
    {
        if(n==0)break;
        long int s[N];
        //memset(s,0,sizeof(int)*N);
        long int t;
        cin >> t;
        /*s[0]=t;max = t;min=t;*/
        s[0] = t;
        long int max = t;
        
        for(int i=1;i<n;i++){
            cin >> t;
            s[i] = s[i-1]+t;
            if(s[i]>max)max=s[i];
            for(int j=0;j<i+1;j++)
            {
                if((s[i]-s[j])>max) max = (s[i]-s[j]);
            }
        }
        cout << max << endl;

    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int &x : v) cin >>x;

    for (int i = 1; i < n; i++) {
        v[i] = v[i] + v[i-1];
    }

    int Max = v[0];    
    int a = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            Max = max(Max, v[j] - a);
        }
        a = v[i];
    }

    cout << Max << endl;

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
using namespace std;

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		vector<int> a(n);
		rep(i,0,n) cin>>a[i];
		int MAX=a[0];
		rep(i,0,n){
			int sum=0;
			rep(j,i,n){
				sum+=a[j];
				MAX=max(MAX,sum);
			}
		}
		o(MAX);
	}
}

C++: 
#include<iostream>

using namespace std;

int main() {
  int a[5000], n, i, j, result, tmp;
  while(cin >> n && n) {
    for(i = 0; i < n; i++) cin >> a[i];
    for(i = 1; i < n; i++) a[i] += a[i-1];
    result = a[n-1];
    for(i = n-1; i >= 0; i--)
      {
	if (a[i] > result) result = a[i];
	for(j = 0; j < i; j++)
	  if ((tmp = a[i] - a[j]) > result) result = tmp;
      }
    cout << result << endl;
  }
  return 0;
}