Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

C++: #include <iostream>
#define TYPE long int
using namespace std;

int main(){
  int n;
  TYPE a[5010], s[5010];
  while(cin>>n && n){
    for( int i=1;i<=n;i++ )
      cin >> a[i];

    TYPE mx = a[1];
    for( int i=1;i<=n;i++ ){
      s[i] = a[i];
      mx = max(mx, s[i]);
      for( int j=i+1;j<=n;j++ ){
	s[j] = s[j-1] + a[j];
	mx = max(mx, s[j]);
      }
    }

    cout << mx << endl;
  }
  return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  while (cin >> n, n) {

    vector<int> dp(n+5);
    int maxv = -INF;
    reps(i, 1, n) {
      int a;
      cin >> a;
      dp[i] = max(dp[i-1] + a, a);
      chmax(maxv, dp[i]);
    }

    cout << maxv << "\n";
  }

  return 0;
}

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

int main()
{
	int a;
	while(1){
		cin>>a;
		if(a==0){
			break;
		}
		int n[5000];
		for(int i=0;i<a;i++){
			cin>>n[i];
		}
		int max_ret = -1<<29;
		int dp[5000];
		dp[0] = n[0];
		for(int i=1;i<a;i++){
			if(dp[i-1]>0){
				dp[i] += dp[i-1] + n[i];
			}else{
				dp[i] = n[i];
			}
			max_ret = max( dp[i], max_ret);
		}
		
		cout<<max_ret<<endl;
	}
	
	
	return 0;
}

C++: //#define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n;
    int a[5005];
    while(cin >> n, n) {
        memset(a, 5005, 0);
        rep(i, n) cin >> a[i];
        int s[5005];
        s[0] = 0;
        REP(i,1,n+1) s[i] = s[i-1] + a[i-1];
        int ans = -INF;
        rep(i,n) {
            REP(j,i,n+1) ans = max(ans, s[j]-s[i]);
        }
        P(ans);
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[5001];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}

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

int main(){

  int n;
  long long int count,maxu;

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

    long long int numbers[n];
    for(int i=0;i<n;i++)
      cin >> numbers[i];
    maxu = count = 0;

    for(int i=0;i<n;i++){
      count += numbers[i];
      maxu = max(count,maxu);
      if(count<0)
	count = 0;
    }
    if(count>0)
      maxu = max(count,maxu);

    cout << maxu << endl;

  }
  
  return 0;
}

C++: /*
 * AOJ-Volume0-0022
 */
#include <iostream>
#include <limits.h>
#include <vector>
#include <cstdio>

using namespace std;

typedef long long ll;

/*
 * Find maximum sum.
 *   array: number list
 */
int findMaximumSum(vector<int> &array){
  int sumValue = array[0];
  int maxValue = INT_MIN;
  int length = array.size();

  for(int i = 1; i < length; i++){
    int value = array[i];

    if(sumValue < 0){
      sumValue = value;
    }else{
      sumValue += value;
    }

    if(maxValue < sumValue){
      maxValue = sumValue;
    }
  }

  return maxValue;
}

void solve(int n){
  vector<int> a(n);

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

  printf("%d\n", findMaximumSum(a));
}

int main(){
  int n;

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

    solve(n);
  }

  return 0;
}

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

using namespace std;

int main(void){
	int n, a[5000], res[5000], sum, i, j, ans;
	while(1){
		scanf("%d",&n);
		if(!n){
			break;
		}
		for(i = 0;i < n;i++){
			scanf("%d",&a[i]);
		}
		sum = 0;
		for(i = 0;i < n;i++){
			sum += a[i];
			res[i] = sum;
		}
		ans = res[0];
		for(i = 0;i < n;i++){
			ans = max(ans,res[i]);
			for(j = 0;j < i;j++){
				ans = max(ans,res[i] - res[j]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main() {
	int n;
	vector<int> r;
	while (true)
	{
		scanf("%d", &n);
		if (n==0)break;
		int max=-2147483648,now=0,in=0;
		for (int i=0; i<n; i++)
		{
			cin >> in;
			now += in;
			if (now > max) max=now;
			if (now < 0) now=0;
		}
		r.push_back(max);
	}
	for (int i=0; i<r.size(); i++)
	{
		cout << r[i] << endl;
	}
	return 0;
}