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;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n;
  while(cin >> n,n){
    vi a(n),sum(n+1,0);
    REP(i,n){
      cin >> a[i];
      sum[i+1] = sum[i]+a[i];
    }
    int ans = INT_MIN;
    REP(i,n+1)FOR(j,i+1,n+1){
      maxs(ans,sum[j]-sum[i]);
    }
    cout << ans << endl;
  }
}

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

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

C++: /*??£?¨?*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int main()
{
	int max = 0, n, a[5001] = {0},max_=0;
	while (cin >> n, n != 0)
	{
		max_ = 0;
		max = -1000000000000000000;
		rep(i, n)
			cin >> a[i];
		rep(i, n)
		{
			for (int j = i; j < n; j++)
			{
				max_ += a[j];
				if (max < max_)
					max = max_;
			}
			max_ = 0;
		}
		cout << max << endl;
	}
	return 0;
}

C++: /*****include*****/
#include <iostream>
#include <fstream>
#include <string>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	int n;
	long int *numbers;
	long int sum;
	long int max_sum;
	/*****処理部*****/
	while(1){
		cin >> n;
		if(n == 0)	break;
		numbers = new long int [n];
		cin >> numbers[0];
		max_sum = numbers[0];
		for(int i=1;i<n;i++){
			cin >> numbers[i];
			sum = 0;
			for(int j=i;j>=0;j--){
				sum += numbers[j];
				if(sum > max_sum)	max_sum = sum;
			}
		}
		cout << max_sum << endl;
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <climits>
using namespace std;

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

C++: /*
?????????: Maximum Sum Sequence
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0022&lang=jp
?????°: 
19:13:12 ?°?????????§??????
19:26:09 ?°??????????????????§???????´????????????????
19:26:28 ????´???????????°??????????????´????????????§????????????????????¨??¢?´¢??§5000^2 ... ????????????
19:32:27 ???????????????
*/
#include <iostream>
#include <vector>
using namespace std;


int main()
{
	while(true){
		int n; cin >> n; if(n == 0) {return 0;}
		vector<int> arr;
		for(int i=0; i<n; i++) {
			arr.push_back(0);
			cin >> arr[i];
		}

		vector<int> sums;
		// sums[0] = 0;
		// sums[1] = sums[0] + arr[0]
		sums.push_back(0);
		for(int i=0; i<n; i++) {
			sums.push_back(sums[i] + arr[i]);
		}

		int ans = -100000;
		for(int i=0; i<n; i++) { 
			for(int j = i+1; j <= n; j++){
				ans = max(ans, sums[j] - sums[i]);
			}
		}

		cout << ans << endl;
	}
}

C++: #include <iostream>

int main()
{
    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) break;

        int a[5000];
        for (int i = 0; i < n; ++i) std::cin >> a[i];

        int max = a[0];
        for (int i = 0; i < n - 1; ++i) {
            int sum = a[i];
            if (max < a[i]) max = a[i];
            for (int j = i + 1; j < n; ++j) {
                sum += a[j];
                if (max < sum) max = sum;
            }
        }
        std::cout << max << std::endl;
    }
}

C++: // includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n;
  while(true){
    cin >> n;
    if(n == 0)break;
    vector<ll> a, sum;
    rep(i, n){
      ll x;
      cin >> x;
      a.pb(x);
      if(i > 0)sum.pb(sum[i-1] + x);
      else sum.pb(x);
    }
    ll res = - inf;
    rep(i, n){
      FOR(j, i, n){
        ll tmp = sum[j];
        if(i > 0)tmp -= sum[i - 1];
        res = max(res, tmp);
      }
    }
    cout << res << endl;
  }
	return 0;
}

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

int main() {
	int n;
	while (cin >> n && n) {
		int a[5001], min, max_a;
		min = a[0] = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (i == 1) max_a = a[i] - a[0];
			a[i] += a[i - 1];
			if (a[i] - min > max_a) max_a = a[i] - min;
			if (a[i] < min) min = a[i];
		}
		cout << max_a << endl;
	}
}

C++: #include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n;
    int A[5000];
    while (cin >> n && n)
    {
        for (int i = 0; i < n; i++)
        {
            cin >> A[i];
        }
        int S[5000];
        S[0] = A[0];
        int max = A[0];
        for (int i = 1; i < n; i++)
        {
            S[i] = S[i - 1] + A[i];
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = i; j < n; j++)
            {
                int sum = 0;
                if (i != 0)
                {
                    sum = S[j] - S[i - 1];
                }
                else
                {
                    sum = S[j];
                }
                if (max < sum)
                {
                    max = sum;
                }
            }
        }
        cout << max << endl;
    }
}