Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var infty = 100000 * 2
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	scanner.Scan()
	return strconv.Atoi(scanner.Text())
}

func findMaximumSubarray(arr []int) int {
	currentMaxSum, maxSumContainsTail := -infty, -infty

	for j := range arr {
		if arr[j] > maxSumContainsTail+arr[j] {
			maxSumContainsTail = arr[j]
		} else {
			maxSumContainsTail += arr[j]
		}
		if currentMaxSum < maxSumContainsTail {
			currentMaxSum = maxSumContainsTail
		}

		// fmt.Println(arr[j], currentMaxSum, maxSumContainsTail)
	}
	return currentMaxSum
}

func main() {
	scanner.Split(bufio.ScanWords)
	for {
		size, _ := nextInt()
		if size == 0 {
			break
		}

		arr := make([]int, size)
		for i := range arr {
			n, _ := nextInt()
			arr[i] = n
		}

		maximumSum := findMaximumSubarray(arr)
		fmt.Println(maximumSum)
	}
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        int data[10000]={};
        rep(i,n) cin>>data[i];
    
    
        int maxi=-999999999;
        int dp[5003][5003]={};
        rep(i,n){
            for(int j=i;j<n+1;j++){
                if(i-1>=0){
                    dp[i][j]=dp[i][j-1]+data[j-1];
                    maxi=max(maxi,dp[i][j]);
                }
            }
        }
        cout<<maxi<<endl;
    }
    return 0;
}

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;
    }
}