Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  vector<int> sum;
  int n;
  int input;

  while(cin>>n){
    if(n==0)break;
    vector<int> array;
    for(int i=0;i<n;i++){
      cin>>input;
      array.push_back(input);
    }
    vector<int> now;
    for(int i=0;i<n;i++){
      int a=0;
      for(int j=0;j<=i;j++){
	a+=array[j];
      }
      now.push_back(a);
    }
    int ma=0;
    for(int i=0;i<n;i++){
      if(i<n-1){
	ma=max(now[i],now[i+1]);
      }
    }
    sum.push_back(ma);
  }
  vector<int> ans;
  int i=0;
  int size=sum.size();
  while(!sum.empty()){
    ans.push_back(sum[size-1-i]);
    sum.pop_back();
    i++;
  }
  i=0;
  while(!ans.empty()){
    cout<<ans[size-1-i]<<"\n";
    ans.pop_back();
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int n;
int a[50001];
int S[50001];


int main(){

while(cin >> n && n > 0){


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

  S[0] = 0;
  for (int i = 0; i < n ; ++i)
  {
    S[i + 1] = S[i] + a[i];
    
  }

int max = -100000;
  for (int i = 0; i < n + 1; ++i)
  {
    for (int k = 0; k < i ; ++k)
    {
      if(S[i] - S[k] > max) max = S[i] - S[k];
    }
  }

  cout << max << endl;

  }
}

C++: #include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;

#define ull unsigned long long
#define ll long long
#define rep(i,j) for(int i=0;i<j;++i)
#define loop(i,a,j) for(int i=a;i<j;++i)
#define mpi(it,table,T,E) for(map<T,E>::iterator it = table.begin();it!=table.end();++it)
#define PI 3.141592654
/*
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
*/
#define N 5005

bool visited[N][N];
int data[N];

int solve(int i,int j,int sum){
	if( i == j) return sum;
	if(visited[i][j])return sum;
	
	int a = max(sum,solve(i+1,j,sum-data[i]));
	int b = max(sum,solve(i,j-1,sum-data[j]));

	visited[i][j] = true;
	return max(a,b);
}


int main(){
	int n;
	while(scanf("%d",&n),n){
		memset(visited,0,sizeof(visited));
		int sum = 0;
		rep(i,n){
			scanf("%d",&data[i]);
			sum += data[i];
		}
		sum = solve(0,n-1,sum);
		printf("%d\n",sum);	
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<int> a;
    for(int i=0,j; i<n; i++){
      cin >>j;
      a.push_back(j);
    }
    for(int i=1; i<=n; i++) a[i]+=a[i-1];
    int m = 0,M = a[0],ans = a[0];
    for(int i=0; i<n; i++){
      M = max(M,a[i]);
      ans = max(ans,M-m);
      m = min(m,a[i]);
    }
    cout <<ans<<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;

int main(){
	int N;
	int x;
	while(cin>>N&&N){
		int index=0;
		int ans = 0;
		int sum[N+1];
		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-2]);
			}
		}
		cout<< ans <<endl;
	}
}

C++: #include<iostream>
#include<vector>

int main() {
	int n;
	while (std::cin >> n) {
		if (n == 0) break;
		std::vector<int> a;
		for (int i = 0; i < n; ++i) {
			int ai;
			std::cin >> ai;
			a.push_back(ai);
		}
		// ここをかく
		int dp[6000], max;
		dp[0] = max = a[0];
		for (int i = 1; i < n; i++) {
			if (dp[i - 1] >= 0) {
				dp[i] = dp[i - 1] + a[i];
			}
			else {
				dp[i] = a[i];
			}
			max = max > dp[i] ? max : dp[i];
		}

		std::cout << max << std::endl;
	}

	return 0;
}

C++: //#define _USE_MATH_DEFINES
//#include <cmath>
#include <iostream>
//#include <stdio.h>
//#include <stdlib.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <time.h>
//#include <sstream>
//#include <queue>

using namespace std;


int main(){

	int n, buf;
	long long ans, sum;
	vector <int> p;


	while (1){
		p.clear();
		sum = 0;
		ans = -100000;

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

		for (int i = 0; i < n; i++){
			cin >> buf;
			p.push_back(buf);
		}

		for (int left = 0; left < n; left++){
			if (p[left] >= 0){
				for (int right = left; right < n; right++){
					if (p[right] >= 0){
						for (int i = left; i <= right; i++){
							sum += p[i];
						}
						if (sum > ans) ans = sum;
						sum = 0;
					}
				}
			}
		}

		cout << ans << endl;

	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int s[5001];

int main()
{
    int n;

    while (cin >> n, n) {
        memset(s, 0, sizeof(s));

        for (int i = 1; i <= n; ++i) {
            int a; cin >> a;
            s[i] = a + s[i - 1];
        }

        int ma = INT_MIN;

        for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
            ma = max(ma, s[i] - s[j - 1]);
        }

        cout << ma << endl;
    }
}

C++: #include <iostream>
#include <vector>

using namespace std;

inline int max (int a, int b) {
    return a > b ? a : b;
}

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