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 <cstdio>
#include <algorithm>
using namespace std;

int main(){
	const int MAX_n = 5000;
	int n, a[MAX_n + 1], z, beg, res;
	
	while(true){
		scanf("%d", &n);
		
		if(n == 0) return 0;
		
		a[0] = 0;
		for(int i = 1; i <= n; i++){
			scanf("%d", &z);
			a[i] = z + a[i - 1];
		}
		
		beg = 0;
		res = -100000;
		for(int i = 1; i <= n; i++){
			beg = min(beg, a[i - 1]);
			res = max(res, a[i] - beg);
		}
		
		printf("%d\n", res);
	}
}

C++: #include <stdio.h>

int main()
{
	int n, x, p, i, j, k;
	
	while(scanf("%d", &n) != 0){
		if (n == 0) break;

		int a[n];

		for(int i = 0; i < n; i++){
			scanf("%d", &a[i]);
		}

		x = a[0];

		for(i = 1; i <= n; i++){
			for(j = 0; j < n-i+1; j++){
				if(j == 0 || a[j+i-1] > a[j-1]){
					p = 0;

					for(k = 0; k < i; k++){
						p += a[j+k];
					}

					if(x < p) x = p;
				}
			}
		}

		printf("%d\n", x);
	}

	return 0;
}

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

using namespace std;
int length=0;
int* sums;

int main(){
  string str="";
  while(1){
  cin>>length;
  if(length==0)break;
  sums=new int[length+1];
  sums[0]=0;
  int s=0;
  for(int i=0;i<length;i++){
    int v=0;
    cin>>v;
    s+=v;
    sums[i+1]=s;
  }
  int max=INT_MIN;
  for(int i=0;i<length+1;i++){
    for(int j=i;j<length+1;j++){
      int diff=sums[j]-sums[i];
      if(diff>max){
        max=diff;
      }
    }
  }
  str+=to_string(max)+"\n";
  }
  cout<<str;
  return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		int sum=0,a[5001];
		vector<int>anss(0);
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++){
			sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				anss.push_back(sum);
			}
		}
		sort(anss.begin(),anss.end(),greater<int>());
		cout<<anss[0]<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
  int n,i,j,k,max,sum;
  while(1){
    int max=-100000;
    cin>>n;
    int a[n];
    if (n==0) break;
    for (i=0;i<n;i++){
      cin>>a[i];
    }
    for (i=0;i<n;i++){
      sum=0;
      for (j=0;j<n-i;j++){
        sum=sum+a[i+j];
        if (max<sum) max=sum;
      }
    }
    cout<<max<<endl;
  }
}

C++: #include<iostream>
#include<cstring>
using namespace std;
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
    long int s[N];
    int n;
    while(cin >> n &&n)
    {
        memset(s,0,sizeof(int)*N);
        int t;
        long int max = 0;
        long int min = 0;
        for(int i=0;i<n;i++){
            cin >>t;
            s[i+1] = s[i]+t;
            if(max<s[i+1])max = s[i+1];
            if(min>s[i+1])min = s[i+1];
        }
        cout << max -min << endl;

    }

    return 0;
}

C++: #include <iostream>

#include <vector>

#include <algorithm>

#include <sstream>

#include <string>

#include <cmath>

#include <list>

#include <set>
#include <cstdlib>
using namespace std;

int in() {int x; cin >> x; return x;}

template <typename T> class SegTree

{

public:

	int n;

	T T_max;

	vector<T> dat;

	SegTree(int n_, T t_max)

	{

		int n = 1;

		T_max = t_max;

		while (n < n_)n *= 2;

		for (int i = 0; i < 2 * n - 1; i++)dat.push_back(t_max);

	}

	void update(int k, T a)

	{

		k += n - 1;

		dat[k] = a;

		while (k > 0)

		{

			k = (k - 1) / 2;

			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);

		}

	}



	//[a,b)

	T query(int a, int b)

	{

		return _query(a, b, 0, 0, n);

	}



private:

	T _query(int a, int b, int k, int l, int r)

	{

		if (r <= a || b <= l)return T_max;

		if (a <= l && r <= b)return dat[k];

		else

		{

			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);

			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);

			return min(vr, vl);

		}

	}

};


int main()
{
	int n;
	while (cin >> n && n)
	{
		vector<long long> a; a.push_back(0);
		long long ans = -999999999999;
		for (long long i = 0; i < n; i++)
		{
			a.push_back(in());
		}

		for (long long i = 1; i < n + 1; i++)
		{
			a[i] += a[i - 1];
		}

		for (long long l = 0; l < n + 1; l++)
		{
			for (long long r = l + 1; r < n + 1; r++)
			{
				ans = max(ans, a[r] - a[l]);
			}
		}
		cout << ans << endl;


	}
}

C++: /* AOJ 0022 Maximum Sum Sequence */

#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;

void update(int i, int x);
void init();

const int MAX_N = 5000;
const int MIN_A = -100000;

int max_sum[MAX_N + 1];

int
main()
{
    for (;;) {
        int n, i;

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

        init();
        for (i = 1; i <= n; i++) {
            int a;

            cin >> a;
            update(i, a);
            cout << max_sum[i] << " ";
        }
        cout << endl;

        cout << *max_element(max_sum + 1, max_sum + n + 1) << endl;
    }

    return 0;
}

void
update(int i, int a)
{
    max_sum[i] = max(max_sum[i - 1] + a, a);
}

void
init()
{
    max_sum[0] = INT_MIN - MIN_A + 1;
}

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

using namespace std;

int main()
{
    int n;
    while (cin >> n && n != 0) {
        int *a = new int[n];
        int m;
        for (int i = 0; i < n; i++) {
            int t;
            cin >> t;
            a[i] = t;
        }
        m = a[0];
        for (int j = 0; j < n; j++) {
            int t = 0;
            for (int k = j; k < n; k++) {
                t += a[k];
                if (m < t) m = t;
            }
        }
        delete [] a;
        cout << m << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        ll N;
        cin >> N;
        if (N == 0)
            break;
        vector<ll> A(N);
        REP(i, N) {
            cin >> A[i];
        }
        ll s = 0;
        ll sum = 0;
        ll ans = -INF;
        REP(i, N) {
            sum += A[i];
            while (sum <= 0 && s < i)
                sum -= A[s++];
            while (A[s] < 0 && s < i)
                sum -= A[s++];
            ans = std::max(ans, sum);
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
  

  int dataSets;

  while(true){
    vector<int> a;
    cin >> dataSets;
    if(dataSets==0){break;}
    for(int i=0;i<dataSets;i++){
      int tmpa;
      cin >> tmpa;
      a.push_back(tmpa);

    }

    int tmax=0;
    // i?????§????????§?????????????????????
    vector<int> tmpMax(dataSets + 1,0);
    tmpMax[0] = 0;
    for(int i=1;i<dataSets+1;i++){
      tmpMax[i] += tmpMax[i-1] + a[i-1];
    }

    for(int i=0;i<dataSets+1;i++){
      for(int j=0;j<i;j++){
	tmax = max(tmax, tmpMax[i]-tmpMax[j]);
      }
    }
    
    // for(int i=0;i<dataSets+1;i++){
      // for(int j=i;j<dataSets;j++){
	// tmax = max(tmax, tmpMax[j+1] - tmpMax[i]);
      // }
    // }
    
    cout << tmax << endl;
    
  }

  return 0;

}