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 <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;i<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;
        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>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
        vi v(n+1,0);
        rep(i,n)cin>>v[i];
        ll ans=0;
        for(int i=0;i<n;i++){
            ll temp=0;
            for(int j=i;j<n;j++){
            for(int k=i; k<=j;k++)temp+=v[k];
            ans=max(ans,temp);
                temp=0;
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
  // ifstream cin("../test.txt");
  int n;
  while (true) {
    cin >> n;
    if (!n) break;
    vector<int> a(n);
    vector<int> sub_sum(n+1); // a[0] + ... + a[i]
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sub_sum[0] = 0;
    int max_sum = -1000000000;
    for (int i = 0; i <= n; i++) {
      sub_sum[i] = sub_sum[i-1] + a[i-1];
    }
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j < i; j++) {
        max_sum = max(max_sum, sub_sum[i] - sub_sum[j]);
      }
    }
    cout << max_sum << endl;
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const double PI = 3.141592653589793238462643383279502884L;
const int LARGE_PRIME = 1000000007;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i,a,cont,next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i,a,b,s) repfn(i,a,i<b,i+s)
#define repab(i,a,b) repby(i,a,b,1)
#define rep(i,b) repab(i,0,b)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  for (;;) {
    int n;
    vi v;

    cin >> n;
    if (!n)
      break;

    while (n--) {
      int tmp;
      cin >> tmp;
      v.pb(tmp);
    }

    vi w(v);
    for (int i = 1; i < sz(v); i++) {
      v[i] = max(v[i-1] + v[i], v[i]);
    }
    cout << *max_element(all(v)) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#define N 5000
using namespace std;

int main(){
  int n, num, a, maxx;
  int ans[N], ac;
  ac = 0;

  while(cin >> n){
    if(n==0){
      ans[ac] = -100001;
      break;
    }

    num = maxx = 0;

    for(int i=0;i<n;i++){
      cin >> a;
      num += a;
      if(num<0) num = 0;
      maxx = max(maxx,num);
    }
    ans[ac] = maxx;
    ac++;
  }

  for(int i=0;ans[i]!=-100001;i++)
    cout << ans[i] << endl;

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

using namespace std;

long int a[5000],ma,n;

int main()
{
	
	while(cin >> n, n)
	{
		ma = INT_MIN;
		
		for( int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		
		for( int j = 0; j < n; j++)
		{
			int sum = 0;
			
			for( int i = j; i < n; i++)
			{
				sum += a[i];
				
				if( sum > ma )
					ma = sum;
				
			}
		}
		
		cout << ma << endl;
	}
	
	return 0;
}

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

int main() {
    int n, a, sum[5010];
    while (cin >> n, n) {
        memset(sum, 0, sizeof sum);
        cin >> a;
        sum[0] = a;
        for (int i=1; i<n; ++i) {
            cin >> a;
            sum[i] = sum[i-1] + a;
        }
        int mx = -100000;
        for (int i=0; i<n; ++i) {
            for (int j=i; j<n; ++j) {
                if (i-1 < 0) {
                    mx = max(mx, sum[j]);
                } else {
                    mx = max(mx, sum[j] - sum[i-1]);
                }
            }
        }
        cout << mx << endl;
    }
    return 0;
}

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

using namespace std;

template <typename Type>
long long Maximum_Sum_Sequence(Type N[], int size)
{
	long long max = LLONG_MIN;

	for (int i = 0; i < size; i++)
	{
		long long sum = 0;

		for (int j = i; j < size; j++)
		{
			sum += N[j];

			if (sum > max) { max = sum; }
		}
	}

	return max;
}

int main()
{
	const int DATASETS = 1000;

	int n[DATASETS], a[DATASETS][5000], c = 0;

	while (true)
	{
		cin >> n[c];

		if (n[c] == 0) { break; }

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

		c++;
	}

	for (int i = 0; i < c; i++)
	{
		cout << Maximum_Sum_Sequence(a[i], n[i]) << endl;
	}

	return 0;
}