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++: //#define _USE_MATH_DEFINES
//#include <cmath>
#include <iostream>
//#include <stdio.h>
//#include <stdlib.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <time.h>
//#include <sstream>
//#include <queue>

using namespace std;


int main(){

	int n, buf;
	long long ans, sum;
	vector <int> p;


	while (1){
		p.clear();
		sum = 0;
		ans = -100000;

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

		for (int i = 0; i < n; i++){
			cin >> buf;
			p.push_back(buf);
		}

		for (int left = 0; left < n; left++){
			if (p[left] > 0){
				for (int right = left; right < n; right++){
					if (p[right] > 0){
						for (int i = left; i <= right; i++){
							sum += p[i];
						}
						if (sum > ans) ans = sum;
						sum = 0;
					}
				}
			}
		}

		cout << ans << endl;

	}

	return 0;
}

C++: /* AOJ 0022*/

#include<iostream>
#include<queue>
using namespace std;

int m;
int n;

void calc(int *data,int num,int sum){
	if(sum>=m){
		m=sum;
	}
	if(num==n){
		return;
	}
	else{
		calc(data,num+1,sum+data[num]);
	}
}

int main(){

	queue<int> ans;

	while(cin>>n){
		if(n==0){
			break;
		}
		int *data = new int[n];
		m=0;
		for(int i=0;i<n;i++){
			cin>>data[i];
		}

		for(int i=0;i<n;i++){
			calc(data,i,0);
		}
		ans.push(m);
	}

	int size=ans.size();
	for(int i=0;i<size;i++){
		cout<<ans.front()<<endl;
		ans.pop();
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>

using namespace std;


int sumarray(int *array, int idx1, int idx2);


int main(){
  int n, Max, ibuf;
  int *List;

  //ifstream ifs("input.txt"); // for debug

  cin >> n;
  while(1){

    // allocate and set value //////////////////////////////
    List = new int[n];
    for(int i=0; i<n; i++) cin >> List[i];

    // solve part //////////////////////////////////////////
    Max = 0;
    for(int l=1; l<=n; l++){
      ibuf = sumarray(List, 0, l);
      if(ibuf > Max) Max = ibuf;
      for(int i=0; i<n-l; i++){
	ibuf += List[i+l] - List[i];
	if(ibuf > Max) Max = ibuf;
      }
    }

    // deallocate //////////////////////////////////////////
    delete List;

    // output //////////////////////////////////////////////
    cout << Max;

    // for next loop //////////////////////////////////////
    cin >> n;
    if(n == 0) break;
    else cout << endl;

  }
  return 0;
}


int sumarray(int *array, int idx1, int idx2){ // sum array[idx1] ~ array[idx2-1]
  int ret = 0;
  for(int i=idx1; i<idx2; i++){
    ret += array[i];
  }
  return ret;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1 << 31;
double EPS = 1e-9;
// BEGIN //////////////////////////////////////////////////////////////


int main() {
	while (true) {
		int N = nextInt();
		if (N == 0) break;
		int score = nextInt();
		int score_max = -INF;
		REP(i, N - 1) {
			int d = nextInt();
			score = max(score + d, d);
			score_max = max(score, score_max);
		}
		PRINT(score_max);
	}

	return 0;
}

// END   //////////////////////////////////////////////////////////////

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

int main(){
	int n;
	cin >> n;
	while(n != 0){	

		int a[n];
		int sum[n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				sum[i][j] = 0;
			}
		}

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

		for(int i = 0; i < n; i++){
			sum[i][0] = a[i];
			for(int j = 0; j < n - i; j++){
				sum[i][j+1] = sum[i][j] + a [i+j+1];
				maximum = max(maximum, sum[i][j]);
			}
		}
		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

double dot(P a,P b){return real(conj(a)*b);};
double cross(P a,P b){return imag(conj(a)*b);};

int main(){
  int n;
  while(~scanf("%d",&n)){
    if(n==0)break;
    ll cur = 0;
    ll mx = 0;
    REP(i,n){
      ll x;
      cin>>x;
      cur = max(cur,cur+x);
      cur = max(cur,x);
      mx = max(mx,cur);
    }
    cout<<mx<<endl;
  }
  return 0;
}

C++: // start 20:09
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

#define REP(i, n) for ( int i = 0; i < n; i++ )

using namespace std;

int sum(vector<int> &nums, int oft, int len) {
    int ret = 0;
    for ( int i = oft; i < len; i++ ) {
        ret += nums[oft+i];
    }
    return ret;
}

int main() {
    int n;
    
    while(cin >> n, n) {
        int max_n;
        vector<int> nums(n);

        REP(i, n) cin >> nums[i];
        
        max_n = nums[0];

        REP(oft, n) REP(len, n-oft) {
            max_n = max(max_n, sum(nums, oft, len));
        }
        cout << max_n << endl;
    }

    return 0;
}

C++: #include <stdio.h>

int main(void) {

  int n;

  int a[6000];

  while(1) {

    int max_a=0;
    int sum;

    int i,j;

    scanf("%d",&n);
    getchar();

    if(n==0) break;

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

    //for(i=0;i<n;i++) printf("%d ",a[i]);

    for(i=0;i<n;i++) {

      sum=0;

      for(j=i;j<n;j++) {

	sum+=a[j];

	if(max_a<sum) max_a=sum;
	//printf("%d ",max_a);
      }

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

  }

  return 0;

}