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 <iostream>
#include <algorithm>
#include <vector>

template <typename Iterator>
auto findMaximumSum (Iterator begin , Iterator end) -> long long
{
    long long res = * begin;
    auto tmp = res;
    for (auto ite = begin + 1; ite != end; ++ ite)
    {
        tmp += * ite;
        res = std::max (res , tmp);
    }
    return res;
}

auto main () -> int
{
    int n;
    while (std::cin >> n && n)
    {
        std::vector <int> a (n);
        for (auto && elem : a)
        {
            std::cin >> elem;
        }
        long long ans = a [0];
        for (auto ite = a.begin (); ite != a.end (); ++ ite)
        {
            auto tmp = findMaximumSum (ite , a.end ());
            ans = std::max (ans , tmp);
        }
        std::cout << ans << std::endl;
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<int>in(n);
    rep(i,n)cin>>in[i];
    int max=0;
    rep(i,n){
      int sum=0;
      loop(j,i,n){
	sum+=in[j];
	if(max<sum)max=sum;
      }
    }
    cout<<max<<endl;
  }


}

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<iostream>
#include<algorithm>
using namespace std;

int main(){
	long long int n;
	
	while(cin>>n,n){
		long long int max=0;
		long long int sum[n];
		long long int t;
		int i;
		for(i=0;i<n;i++)cin>>sum[i];
		for(i=t=0;i<n;i++){
			if(t<0)t=sum[i];else t+=sum[i];
			if(max<t)max=t;
		}
		cout<<max<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

ll INF = 1LL << 63;
double EPS = 1e-9;
// BEGIN //////////////////////////////////////////////////////////////


int main() {
	while (true) {
		int N = nextInt();
		if (N == 0) break;
		ll score = nextll();
		ll score_max = -INF;
		REP(i, N - 1) {
			ll d = nextll();
			score = max(score + d, d);
			score_max = max(score, score_max);
		}
		PRINT(score_max);
	}

	return 0;
}

// END   //////////////////////////////////////////////////////////////

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#include <cmath>
#define mp make_pair
#define pii pair<int,int> 
#define ff first
#define ss second

using namespace std;

int n;
int list[10000],dp[10000];
int hasil;

int main()
{
	while(1)
	{
		scanf("%d",&n);
		if(n==0)
		break;
		hasil=-1000000;
		dp[0]=0;
		for(int a=1;a<=n;a++)
		{
			scanf("%d",&list[a]);
		}
		for(int a=1;a<=n;a++)
		{
			if(dp[a-1]>=0)
			{
				dp[a]=dp[a-1]+list[a];
			}
			else
			{
				dp[a]=list[a];
			}
			hasil=max(hasil,dp[a]);
		}
		/*for(int a=0;a<=n;a++)
		{
			printf("%d ",dp[a]);
		}*/
		printf("%d\n",hasil);
	}
	return 0;
}

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

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

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

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

		for (i = 0; i < n; i++)
			cin >> a[i];

		max = INT_MIN;
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n - i; j++)
			{
				for (k = 0; k < n - i; k++)
				{
					sum = 0;
					for (l = k; l <= i; l++)
						sum += a[l];
					if (sum > max) max = sum;
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
int main() {
	long long n, a[5001], rui[5002] = { 0 }, ans[5002], cnt = 0;
	while (1) {
		cnt++;
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
			rui[i+1] = rui[i] + a[i];
		}
		int max;
		max = -100001;
		for (int i = 0; i <= n; ++i) {
			for (int j = i+1; j <= n; ++j) {
				if (rui[j] - rui[i] > max) {
					max = rui[j] - rui[i];
				}
			}
		}
		ans[cnt] = max;
	}
	for (int i = 1; i < cnt; ++i) {
		cout << ans[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
#define N_MAX 5000
int array[N_MAX];
int main(){
	int n;
	int num;
	while(cin>>n&&n){
		int ans=-100000*5000;
		for(int i=0;i<n;i++){
			cin>>num;
			if(i==0)array[i]=num;
			else{
				array[i]=max(array[i-1]+num,num);
			}
			ans=max(ans,array[i]);
		}
		cout<<ans<<endl;
	}
	return 0;
}