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 <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;


int main()
{
	for(int n;cin>>n,n;){
		vector<int>dp;
		dp.pb(0);
		rep(i,n){
			int t;
			cin >> t;
			dp.pb(dp.back()+t);
		}
		int mx=0;
		rp(i,dp){
			REP(j,i+1,dp.size()){
				mx=max(mx,dp[j]-dp[i]);
			}
		}
		cout << mx << endl;
	}
	return 0;
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define HOGE 5000
#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;

int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        int data[HOGE];
        int ma=-INF;
        rep(i,n){
            cin>>data[i];
        }
        for(int i=0;i<n-1;i++){
            int dp[HOGE];
            dp[i]=data[i];
            for(int j=i+1;j<n;j++){
                dp[j]=dp[j-1]+data[j];
                ma=max(ma,dp[j]);
            }
            
        }
        cout<<ma<<endl;
    }

    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 = -10000;
		for (int ai = 0; ai < n - 1; ai++) {
			for (int bi = n-1; 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>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;

int main(){
    int n;
    while(cin >>n && n){
        vector<int> vec(n + 1, 0); FOR(i, 1, n + 1) cin >>vec[i];
        FOR(i, 1, n + 1) vec[i] += vec[i - 1];
        int ans = -1 * INF;
        REP(i, n + 1) FOR(j, i + 1, n + 1) ans = max(ans, vec[j] - vec[i]);
        cout <<ans <<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <algorithm>
#include <cctype>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1e8;
const double pi=acos(-1);

ll n,ans;
vector<ll> dp,num;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		ans=-inf;
		dp=vector<ll>(n);
		num=vector<ll>(n);
		for(int i=0;i<n;i++) cin>>num[i];
		dp[0]=num[0];
		for(int i=0;i<n-1;i++) dp[i+1]=max(num[i+1],num[i+1]+dp[i]);
		for(int i=0;i<n;i++) ans=max(ans,dp[i]);
		cout<<ans<<endl;
	}
}

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

int main(){
  int n;
  long long int a, max_, tmp;
  while(true){
    cin >> n;
    if(n==0)
      break;
    max_=0; tmp=0;
    for(int i=0; i<n; i++){
      cin >> a;
      tmp = max(0ll,tmp+a);
      max_ = max(tmp,max_);
    }
    cout << max_ << endl;
  }
  return 0;
}

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

int main(void){
	int n;
	int i;
	int temp;
	int sum[5000];
	int num;
	
	while(1){
		for(i=0; i<5000; i++){
			sum[i] = -100001;
		}
		sum[0] = 0;
		num = 0;
	
		scanf("%d", &n);
		if(n == 0) break;
		
		for(i=0; i<n; i++){
			scanf("%d", &temp);
			if(temp > 0 && sum[num] < 0){
				num++;
				sum[num] = temp;
			}else if(temp > 0){
				sum[num] += temp;
			}else if(temp <= 0 && sum[num] < 0){
				num++;
				sum[num] = temp;
			}else{
				num++;
				sum[num] = sum[num-1] + temp;
				if(i == 0 && sum[num-1] == 0) sum[num-1] = -100001;
			}	
		}

		sort(sum, sum + 5000, greater<int>());
		
		printf("%d\n", sum[0]);
		
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
	int n, *a;
	int ans, sum;
	while (1) {
		cin >> n;
		if (n == 0)
			break;
		a = new int[n];
		for (int i = 0; i < n; i++)
			cin >> a[i];
		ans = 0;
		for (int i = 0; i < n; i++) {
			sum = a[i];
			ans = max(ans, sum);
			for (int j = i + 1; j < n; j++) {
				sum += a[j];
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
		delete[] a;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n;

	while (1)
	{
		int a[5001] = {0}, s[5001] = {0}, max = 0;

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

		for (int i=1; i<=n; i++)	//入力
			cin >> a[i];

		for (int i=1; i<=n; i++) {
			for (int j=1; j<=i; j++) {
				s[i] += a[j];		//s[i] = a[1]+a[2]+...+a[i]
			}
		}

		//cout << s[0] << endl;	//Debug

		//int cont = 0;	//Debug
		for (int i=1; i<=n; i++) {
			for (int j=1; j<=i; j++) {
				//if (max < s[i] - s[j-1]) cout << "max = " << s[i] - s[j-1] << endl;	//Debug
				max = (max < s[i] - s[j-1]) ? s[i] - s[j-1] : max;	//区間i,jの和を求めて比較
				//cont++;	//Debug
			}
		}

		cout << max << endl;
		//cout << cont;
	}

	return 0;
}