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 <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>

typedef long long Int;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
using namespace std;

Int aa[10000];
Int dp[10000];


int main(){
	int n;
	while (cin >> n, n){

		fill(aa, aa + 10000, 0);
		fill(dp, dp + 10000, 0);
		REP(i, n){
			cin >> aa[i];
		}


		Int max_i = -999999999;
		dp[0] = max(dp[0], aa[0]);
		max_i = max(max_i, dp[0]);

		for (int i = 1; i < n; ++i){
			dp[i] = max(aa[i], dp[i - 1] + aa[i]);
			max_i = max(max_i, dp[i]);
		}
		cout <<  max_i << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <vector>
#define PB push_back
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using	namespace std;
int n,tmp;
void solve(){
	while(cin >> n  && n!= 0){
		vector <int> data ;
		REP(i,n){
			cin >> tmp;
			data.PB(tmp);
		}
		int sofar = 0 ,end = 0;
		REP(i,n){
			end = max(end+data[i],0);
			sofar = max(end,sofar);
		}
		if(sofar == 0){
			sofar = -10000000;
			REP(i,n)sofar = max(sofar,data[i]);
		}
		cout << sofar <<endl;


	}

}

int main(){
	solve();

}

C++: #include <iostream>

using namespace std;

int main(){
  int n;
  while(true){
    cin>>n;
    if(!n)break;
    int a[n],b[n];
    for(int i=0;i<n;i++){
      cin>>a[i];
      b[i] = 0;
    }
    int k=0;
    for(int i=0;i<n;){
      while(i<n&&a[i]>0){
	b[k] += a[i];
	i++;
      }
      k++;
      if (i>=n)break;
      while(i<n&&a[i]<=0){
	b[k] += a[i];
	i++;
      }
      k++;
    }
    int max = 0;
    for(int i=0;i<k;i++){
      for(int j=i;j<k;j++){
	int sum = 0;
	for(int l=i;l<=j;l++)
	  sum+=b[l];
	if(sum>max)max = sum;
      }
    }
    cout << max << endl;
  }
  return 0;
}

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

#define MAX(X,Y) ((X)>(Y)?(X):(Y))

int main(void){
  long long ans, acc[5001];
  int n;
  
  while (cin >> n){
    if (n==0) break;
    acc[0] = 0;
    for (int i=0; i<n; i++){
      int t;
      cin >> t;
      acc[i+1] = t + acc[i];
    }
    ans = -(1<<31-1);
    for (int i=0; i<n; i++){
      for (int j=0; j<=i; j++){
        int sum = acc[i+1] - acc[j];
        ans = MAX(ans, sum);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int a[5010];
int dp[5010];
int main(){
	while(cin>>n,n){
		for(int i =0;i < n;i++){
			cin>>a[i];
			dp[i+1]=a[i];
		}
		dp[0] = 0;
		int ans = -(1<<25);
		for(int i =1;i <= n;i++){
			dp[i] =max(dp[i-1]+a[i-1],dp[i]);
			ans =max(ans,dp[i]);
		}
		cout <<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main( void )
{
	while (1)
	{
		int n;
		cin >> n;
		if ( n == 0 )
			break;

		bool flag = false;
		int max_value = 0;
		int now = 0;
		for ( int i = 0; i < n; i++ )
		{
			int value;
			cin >> value;
			now += value;
			if ( flag == false )
			{
				max_value = now;
				flag = true;
			}
			max_value = max( now, max_value );
			if ( now < 0 )
				now = 0;
		}

		if ( now > 0 )
			max_value = max( now, max_value );

		cout << max_value << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <limits.h>
using namespace std;
#define N 5000

int main(void)
{
	while(1) {
		int n;
		long an[N] = {0}, sum = 0, max = LONG_MIN;
		cin >> n;

		if(n == 0)	break;

		for(int i = 0; i < n; i++) {
			cin >> an[i];
		}

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

		cout << max << endl;
	}
	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;

ll dp[5000];
int main(){
	memset(dp,0, sizeof(dp));
	int n,a;
	while(1){cin >> n;if(!n)break;
		ll ans=0;
		
		rep(i,n){cin>>a;
			if(dp[i-1]>0)dp[i]=dp[i-1]+a;
			else dp[i] = a;
			ans = max(ans,dp[i]);
		}
		cout<<ans<<endl;
	}

}

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 tmp;
  int all;
  while(1){
    cin >> n;
    if(n == 0) break;
    int num[n];
    for(int i=0;i<n;i++) cin >> num[i];
    tmp = num[0];
    for(int i=0;i<n;i++){
      all = 0;
      for(int j=i;j<n;j++){
	all += num[j];
	if(tmp < all) tmp = all;
      }
    }
    cout << tmp << endl;
  }
}