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 <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> v;
        PUSH(n,v);
        long maxv = -1e9;
        for(int i = 1; i <= n; i++) {
            vector<long> w;
            long j = 0;
            REP(k,i) j += v[k];
            w.push_back(j);
            REP(k,n-i) {
                j += -v[k] + v[i+k];
                w.push_back(j);
            }
            sort(w.begin(), w.end());
            maxv = max(maxv, w[w.size()-1]);
        }
        cout << maxv << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <climits>
using namespace std;
 
int main(){
    int n,a[5001];
    int ans;
    a[0]=0;
    while(cin>>n&&n){
        ans = INT_MIN;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            a[i] += a[i-1];
        }
        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                ans = max(ans,a[j]-a[i-1]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

#define rep(X, Y) for( int X = 0; X < Y; ++X )
#define repi(X, Y, Z) for( int X = Y; X < Z; ++X )

int n;
long long array[5001];
long long max;

int main(){
	while( std::cin >> n, n ){
		max = std::numeric_limits<long long>::min();

		rep( i, n ) std::cin >> array[i + 1];

		rep( i, n ) array[i + 1] += array[i];

		rep( i, n + 1 ) repi( l, i + 1, n + 1 ){
			max = std::max( max, array[l] - array[i] );
		}

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

	return 0;
}

C++: #include <iostream>
using namespace std;
long long int n,a[5000];
int main(){
	int i,j,t,tmp;
	while(cin >> n && n){
		tmp = 0;
		t = 0;
		for(i=0;i<n;i++){
			cin >> a[i];
		}
		for(i=0;i<n-1;i++){
			tmp += a[i];
			for(j=i+1;j<n;j++){
				tmp += a[j];
				if(t < tmp) t = tmp;
			}
			tmp = 0;
		}
		cout << t << endl;
	}
	return 0;
}

C++: //Maximum Sum Sequence
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll INF = 1000000LL;

int main(){
  int n;
  while(true){
    ll max = -INF, tmp = -INF, d;
    cin >> n;
    if(n == 0)break;
    for(int i = 0; i < n; i++){
      cin >> d;
      tmp=(tmp+d > d ? tmp+d : d);
      if(max<tmp)max=tmp;
    }
    cout<<max<<endl;
  }
  return 0;
}

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

typedef vector<int> vi;
typedef long long ll;

int main(){
    int n;
    while(cin >> n && n){
        vi v(n+1);
        rep(i,n){
            int x; cin >> x;
            v[i+1] = x;
            if(i!=0) v[i+1]+=v[i];
        }
        // rep(i,n+1){
        //     cout << v[i] << endl;
        // }
        ll ans=-(1<<30);
        for(int l=0; l<n; l++){
            for(int r=l+1; r<=n; r++){
                ans = max<ll>(ans, v[r]-v[l]);
            }
        }
        cout << ans << endl;
    }
}

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

int main(){
	int n;
	int a;
	int sum;
	int sum2;
	int sum3;
	int max;
	cin >> n;
	while(n){
		cin >> sum;
		cin >> sum2;
		sum += sum2;
		max = sum;
		for(int i=0;i<n-2;i++){
			cin >> sum3;
			sum += sum3;
			sum2 += sum3;
			if(sum < sum2){
				sum = sum2;
			}
			if(sum > max){
				max = sum;
			}
			sum2 = sum3;
		}
		cout << max << endl;
		cin >> n;
	}
	return 0;
}

C++: /*AOJ 0022*/

#include<iostream>
#include<vector>
using namespace std;

int main(){

	int n;

	for(;;){

		cin>>n;

		if(n==0){
			break;
		}

		vector<int> data;
		int max=0;
		int sum=0;
		for(int i=0;i<n;i++){

			int tmp;
			cin>>tmp;

			data.push_back(tmp);

		}

		for(int i=0;i<n;i++){
			sum = 0;
			/*
			if(data.at(i)<0){
				continue;
			}
			*/
			for(int j=i;j<n;j++){
				sum+=data.at(j);
				if(sum>=max){
					max = sum;
				}
			}
		}

		cout<<max<<endl;

	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
int main() {
  int n, input;
  vector<int> input_v;
  vector<int> part_v;
  int max_num = 0;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    input_v.clear();
    while(n--) {
      cin >> input;
      input_v.push_back(input);
    }
    max_num = -1000000;
    for (int i = 0; i < input_v.size(); ++i) {
      for (int len = 2; len <= input_v.size() - i; ++len) {
        for (int m = 0; m < len && i + m < input_v.size(); ++m) {
          part_v.clear();
          for (int k = i; k < i + m; ++k) {
            part_v.push_back(input_v[k]);
          }
          max_num = max(accumulate(part_v.begin(), part_v.end(), 0), max_num);
        }
      }
    }
    cout << max_num << endl;
  }
  return 0;
}

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

int main()
{
	int n,t,mx;
	while(cin >> n, n)
	{
		mx = -(1<<30);
		int dt[5000]={0};
		for(int i=0; i<n; i++)
		{
			cin >> t;
			for(int j=0; j<=i; j++)
			{
				dt[j]+=t;
				mx=max(mx,dt[j]);
			}
		}
		cout << mx << endl;
	}
}

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

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

    int max = INT_MIN;
    int maxBfr = INT_MIN;
    int bfr = INT_MIN;

    for(int i = 0; i < n; i++) {
      int temp;
      cin >> temp;

      if(maxBfr > 0) {
	maxBfr += bfr;
      } else {
	maxBfr = bfr;
      }

      int sum;
      sum = maxBfr+temp;

      if(maxBfr != INT_MIN && sum > max && sum > temp) {
	max = sum;
      } else if(temp > max) {
	max = temp;
      }

      bfr = temp;
    }

    cout << max << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
while(true)
{
int n;
cin >> n;
if(n == 0)return 0;
int numbers[n];
for(int i = 0;i < n;i++)
cin >> numbers[i];
int max = 0;
for ( int i = 0; i < n; i++){
int sum = 0;
for ( int j = i; j < n; j++){
sum += numbers[j];
if(max < sum)max = sum;
}
}
cout >> max >> endl;
}
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int n, a[6000];

int main() {
    for (;;) {
        scanf("%d", &n);
        if (n == 0) return 0;
        rep (i, n) scanf("%d", a+i);
        int m = 0, s = 0, ans = a[0];
        rep (i, n) {
            s += a[i];
            ans = max(ans, s-m);
            m = min(m, s);
        }
        printf("%d\n", ans);
    }
}

C++: #define MINUS -99999999
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
  int n,a[5010],j;
  long long int  sum[5010] = {0},max;
  while(1){
    max = MINUS;
    cin >> n;
    if(n == 0)break;
    for(int i = 1; i <= n; i++){
      cin >> a[i];
      sum[i] = sum[i-1] + a[i];
    }
    for(int i = 0; i < n; i++){
      for(int j = i + 1; j <= n; j++){
	if(max < sum[j] - sum[i]){
	  max = sum[j] - sum[i];
	} 
      }
    }
    printf("%lld\n",max);
  }
}