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

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

vector<long long> num;
long long dp[5000];

void init(){
  for(int i = 0; i < 5000; i++){
    dp[i] = 0;
  }
  num.clear();
}

int main(void){
  while(true){
    long long maximum = 0, n;
    cin >> n;
    if(!n)  break;
    init();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < n; i++){
      dp[i] = max(dp[i-1] + num[i], num[i]);
    }
    
    for(int i = 0; i < n; i++){
      if(dp[i] > maximum) maximum = dp[i];
    }

    cout << maximum << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int stage[100000] = {0};
        for(int i = 1;i <= n; i++){
            scanf("%d",&stage[i]);
        }
        int x = 0;
        int ans = -1000000;
        for(int i = 1;i <= n; i++){
            for(int j = i;j <= n; j++){
                x += stage[j];
                ans = max(ans,x);
            }
            x = 0;
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

template<typename T>
T m(T a, T b) { return a > b ? a : b; }

int main(void) {
    freopen("i.in", "r", stdin);
    int N;
    while(true) {
        cin >> N;
        if(N == 0) break;
        vector<int> v(N);

        for(int i = 0; i < N; i++) cin >> v[i];

        long long mx = -100000L;

        for(int i = 0; i < N; i++) {
            long long tmp = 0L;
            for(int j = i; j < N; j++) {
                tmp += v[j];
                mx = m(mx, tmp);
            }
        }
        cout << mx << endl;
    }
    return 0;
}

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

int main(){
	int n;
	int a;
	int sum;
	cin >> n;
	while(n){
		cin >> sum;
		for(int i=0;i<n;i++){
			cin >> a;
			if(sum < a){
				sum = a;
			}else{
				sum += a;
			}
		}
		cin >> n;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int i;
	long max;
	long total;
	int a[5010];
	int n;
	
	while (scanf("%d", &n), n != 0){
		max = 0;
		total = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
			total += a[i];
			if (total < 0){
				total = 0;
			}
			if (max < total){
				max = total;
			}
		}
		printf("%d\n", max);
	}
	return (0);
}

C++: #include <iostream>

using namespace std;

int main(void){
	int n;
	long long int a[5000]={0};
	while(cin >> n){
		long long int max = 0;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			cin >> a[i];
		}
		for(int i=0;i<n;i++){
			long long int sum = 0;
			for(int j=0;i+j<n;j++){
				sum += a[i+j];
				if(j!=0&&max < sum) max = sum;
			}
		}
		cout << max << "\n";
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[2500];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int l = 0;
    while(cin >> number)
    {
        int a[5010] = {0};
        vector<int>tempmax2(5010,0);
        int temp = 0;
        REP(i,number)
        cin >> a[i];
        for(int j = 0; j<number;j++)
            for(int k = j;k<number;k++)
            {
                for(int l = k;l<number;l++)
                {
                    if(k == l)
                        tempmax2[k] = a[k];
                    else{
                        
                        tempmax2[k] += a[l];
                    }
                    if(temp <= tempmax2[k])
                        temp = tempmax2[k];
                }
            
            }
        //sort(tempmax.begin(),tempmax.end(),greater<int>());
        //sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        //if(tempmax[0]>temp)
            //answer[l] = tempmax[0];
        //else
        // answer[l] = temp;
        printf("%d\n",temp);
        temp = 0;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
int main()
{
	while (!std::cin.eof())
	{
		int n;
		std::cin >> n;
		if (n == 0)
		{
			break;
		}
		std::vector<int>a;
		for (int i = 0; i < n; i++)
		{
			int foo;
			std::cin >> foo;
			if (i == 0 || a.back() * foo < 0)
			{
				a.push_back(foo);
			}
			else
			{
				a.back() += foo;
			}
		}
		int max = -100001;
		if (a.size() == 1)
		{
			max = a[0];
		}
		else
		{
			int begin = a[0] > 0 ? 0 : 1;
			int temp_max = a[begin];
			try
			{
				for (int i = begin;;)
				{
					if (a.at(i + 1) + a.at(i + 2) > 0)
					{
						temp_max += a[i + 1] + a[i + 2];
						i += 2;
					}
					else
					{
						if (max < temp_max)
						{
							max = temp_max;
						}
						temp_max = a[i + 2];
						i += 2;
					}
				}
			}
			catch (std::out_of_range)
			{
				if (max == -100001)
				{
					max = temp_max;
				}
			}
		}
		std::cout << max << std::endl;
	}
	return 0;
}

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

int main(void)
{
	vector<int> numbers;
	int count, tmp, ans[5000], Max;

	while (cin >> count) {
		if (count == 0) break;
		for (int i = 0; i < 5000; i++) ans[i] = 0;
		Max = -100000;
		for (int i = 0; i < count; i++) {
			cin >> tmp;
			for (int j = 0; j <= i; j++) {
				ans[j] += tmp;
				if (Max < ans[j]) Max = ans[j];
			}
		}
		cout << Max << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main( void )
{
  int n,prev,d[5001],ret;
  while( 1 ){
    cin >> n;
    if( n==0 ) break;
    cin >> d[0];
    ret = d[0];
    for( int i=1; i<n; i++ ){
      cin >> d[i];
      for( int j=0; j<i; j++ ) d[j] += d[i];
      ret = max( *max_element( d, d+i ), ret );
    }
    cout << ret << endl;
  }
  return 0;
}