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>

int calcMaxSum(int amount_set);

int main()
{
    while (true) {
        int amount_set;
        std::cin >> amount_set;
        
        if(amount_set == 0) {
            break;
        }
        std::cout << calcMaxSum(amount_set) << std::endl;
    }

    return 0;
}

int calcMaxSum(int amount_set)
{
    const int MAXNUMBER = 100000;//??\????????????????????§??????

    int *data;
    data = new int[amount_set];
    int sum = 0;
    int max = -amount_set * MAXNUMBER;//??????????????????????°?????????§????????????int?????\??????
    int min = 0;//?????????min?????£?????????????????????????????????????????°???????????§???min???0????????????

    for (int number = 0; number < amount_set; number++) {
        std::cin >> data[number];//????????????????????????
        sum += data[number];// ????????´??°

        if (sum > max) {//?????§?????????????????§????????£??????
            max = sum;//?????§????????´??°
        } 
        if (sum < min) {//????°?????????????????°?????????£??????
            min = sum;//????°?????????´??°
        }
    }

    delete [] data;

    return max - min;

}

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

int main()
{

	int n, num;
	vector< int > a;

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

		int Max = -100001;

		a.push_back( 0 );

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

			cin >> num;
			a.push_back( num );

		}

		for( int i = 1; i <= n; i++ ) {

			a[i] = max( a[i], a[i] + a[i - 1] );
			Max  = max( Max, a[i] );
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

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

int main(){
  int n;
  long long int a, max_, tmp;
  while(cin >> n){
    max_=0; tmp=0; tmp=0;
    for(int i=0; i<n; i++){
      cin >> a;
      tmp = max(0ll,tmp+a);
      max_ = max(tmp,max_);
    }
    cout << max_ << endl;
  }
  return 0;
}

C++: #include"bits/stdc++.h"
#define INF LLONG_MAX-1
using namespace std;
typedef long long ll;
??
ll a[100001];
int main(){
	ll n;
	ll cnt = 0;
	scanf("%lld", &n);
	for (ll i = 0; i < n; i++){
		scanf("%lld", &a[i]);
		cnt += a[i];
	}
	ll Max = cnt;
	ll w = 0;
	for (ll i = 0; i < n; i++){
		cnt -= a[i];
		if (Max < cnt) {
			w = i;
			Max = cnt;
		}
	}
	cnt = Max;
	for (ll i = n - 1; i > w; i--){
		cnt -= a[i];
		Max = max(Max, cnt);
	}
	printf("%lld\n", Max);
	return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

int main() {
  int n;

  while(cin >> n, n) {
    VI a(n);
    REP(i, n) cin >> a[i];

    int ans = -1000000;
    REP(i, n) {
      int sum = 0;
      FOR(j, i, n) {
	sum += a[j];
	ans = max(sum, ans);
      }
    }

    cout << ans << endl;
  }
}

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

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

int n;
vector<int> v;

int s[5000][5000];

int main(){
    while(cin>>n,n){
        v=vector<int>(n);
        REP(i,n)cin>>v[i];
        int ans=-(1<<15);
        REP(i,n){
            s[i][i]=v[i];
            ans=max(s[i][i],ans);
            for(int j=i+1; j<n; j++){
                s[i][j]=s[i][j-1]+v[j];
                ans=max(s[i][j],ans);
            }
        }
        cout<<ans<<endl;
    }
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

  template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
    if(n == 0) break;
    vector<int> a(n+1,0);
    int ans =0,res= 0;
    rep(i,n){
      cin >> a[i];
      ans +=a[i];
    }
    rep(i,n){
      vector<int> kt(n+1,0);
      for(int j = i;j<n;++j){
        kt[j] += kt[j-1]+a[j-1];
      }
      ans = max(ans,*max_element(all(kt)));
    }
    cout << ans << endl;
  }
  return 0;
}

C++: //
#include <iostream>
using namespace std;
int main()
{
  int n;
  while(true){
    int a[5000] = {0};
  cin >> n;
  if (n == 0 ) break;
  for (int i = 0; i < n;i++)
    cin >> a[i];
  int sum_max = a[0];
  int sum = 0;
  for (int i = 0; i <n;i++){
    for (int j = i; j < n; j++){
      sum += a[j];    if(sum > sum_max) sum_max = sum;
    }
    int sum = 0;
  }

  }
  cout << sum_max;
    

  }
}

C++: #include <stdio.h>

int seqsum(int n){
	int a = 0;
	int b[5000];
	int c = 0;
	int s = 0;
	scanf("%d", &a);
	b[0] = s = a;

	for(int i=1; i<n; ++i){
		scanf("%d", &a);
		if(s * a >= 0){
			b[c] += a;
		}else{
			b[++c] = s = a;
		}
	}

	int m = b[0] < 0 ? 0 : b[0];
	int sum = m;
	for(int i=1; i<=c; ++i){
		if(sum < 0 && m < b[i]){
			sum = m = b[i];
		}else{
			sum += b[i];
			if(m < sum){
				m = sum;
			}
		}
	}
	return m;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}