Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

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

C++: 
class Max
  def solve
    loop do
      n = get.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 <iostream>
#include <cmath>
#include <algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)

using namespace std;

int main(void){
	long int n , a[5005] , s[5005] , m;
	while (cin >> n && n){
		REP(i,n){
			cin >> a[i];
		}
		s[0] = 0;
		FOR(i,1,n){
			s[i] = s[i-1]+a[i-1];
		}
		m=-100000;
		REP(i,n){
			FOR(j,i+1,n+1){
				if(s[j]-s[i]>m)
					m=s[j]-s[i];
			}
		}
		cout << m << endl;
	}
	return 0;
}

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

int main(){

    while(1){
    int n; cin >> n;
    if(!n) break;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(i > 0) a[i] += a[i - 1];
    }
    a[0] = 0;
    int ans = a[1];
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j <= n; j++){
            ans = max(ans, a[j] - a[i]);
        }
    }

    cout << ans << endl;
    }
    return 0;
}