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----------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>
//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;

//global-----------------------------------------------------------------------------------------------------------------------
LL a, b, n, ans = 0;
vector<LL> ar;
vector<LL> sum_ar;
//#define DEBUG
//function--------------------------------------------------------------------------------------------------------------------

int main() {
	while ( scanf( "%lld", &n ) && n ) {
		sum_ar.PB( 0 );
		ans = 0;
		rep( i, n ) {
			scanf( "%lld", &a );
			ar.PB( a );
			sum_ar.PB( sum_ar[ i ] + a );
		}
		rep( i, n ) {
			FOR( j, i, n ) {
#ifdef DEBUG
				debug(i)
				debug(j)
#endif
				ans = max( ans, sum_ar[ j ] - sum_ar[ i ] );
			}
		}
		printf( "%lld\n", ans );
		sum_ar = vector<LL>();
	}
	return 0;
}

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

int main()
{
	int n=1, count = 0;
	int a[10000],ans[10000];
	while (n != 0) {
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = -10000,sin=1;
		for (int ai = 0; ai < n - 1; ai++) {
			if (a[ai] > 0 || sin == 0) {
				sin = 0;
				for (int bi = n - 1; bi > ai; bi--) {
					sum = 0;
					for (int k = ai; k < bi; k++) {
						sum = sum + a[k];
					}
					if (sum > max) {
						max = sum;
					}
					//cout << ai << " " << bi << endl;
				}
			}
		}
		ans[count] = max;
		count++;
	}
	for (int ci = 0; ci < count-1; ci++) {
		cout << ans[ci] << endl;
	}
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        int plus[5000] = {0}, max = -100001, input;
        rep(i,n){
            cin >> input;
            plus[i]+= input;
            plus[i+1] = plus[i];
            if(max < plus[i]){
                max = plus[i];
            }
        }
        rep(i,n){
            rep(j,i-1){
                if(max < plus[i] - plus[j]){
                    max = plus[i] - plus[j];
                }
            }
        }
        cout << max << endl;
    }
}

C++: 
class Max
  def solve
    loop do
      n = gets.chomp.to_i
      break if n == 0
      
      max = -100000
      sum = 0
      n.times do
        a = gets.chomp.to_i
        sum += a
        if max < sum
          max = sum
        end
        if sum < 0 then 
          sum = 0
        end
      end
      puts max
    end
  end
end
Max.new.solve

C++: #include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(int a=0;a<t;a++) 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        int sum[5001];
        roop(i, n) {
            cin >> sum[i];
            if (i != 0) { sum[i] += sum[i - 1]; }
        }
        int ans = -9000000000;
        for (int i = -1; i < n-1; i++) {
            int sumi = 0;
            if (i != -1)
            {
                sumi = sum[i];
            }
            for (int j = i + 1; j < n; j++) {
 
                int sumj = sum[j];
                ans = max(ans, sumj - sumi);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

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

C++: #include "bits/stdc++.h"
using namespace std;
#define ll long long
#define INF (1<<30)
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		vector<ll> a(n);
		vector<ll> Sum(n);
		for (int i = 0; i < n; i++) cin >> a[i];
		Sum[0] = a[0];
		for (int i = 1; i < n;i++) Sum[i] = a[i] + Sum[i - 1];

		ll ans = -INF;

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

C++: #include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
using namespace std;
typedef vector <long> vlong;

long maxv(vlong &x){
	long tmp=x[0];
	for (int i=1; i<x.size(); i++)
		if (x[i]>tmp) tmp=x[i];
	return tmp;
}

int main(void){
	int n;
	vlong x;
	while (cin>>n){
		long s=LONG_MIN;
		if (n==0) break;
		for (int i=0; i<n; i++){
			long n2;
			cin>>n2;
			for (int j=0; j<x.size(); j++){
				x[j] += n2;
			}
			x.push_back(n2);
			if (i==0 || n2>0) s=max(s, maxv(x));
		}
		cout<<s<<endl;
		x.clear();
	}

	return 0;
}