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>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,a;
  long int s;
  vector<long int> x(10000),m(10000);
  while(cin >>n,n){
    x[0] = m[0] = 0;
    for(int i=1; i<=n; i++){
      cin >>a;
      x[i] = x[i-1]+a;
      m[i] = min(m[i-1],x[i]);
    }
    s = x[1];
    for(int i=1; i<=n; i++) s = max(s,x[i]-m[i-1]);
    cout <<s<<endl;
  }
}

C++: #include <stdio.h>
int array[5000];
int n,i,sum=0,k=0;
void tansaku(int a)
{
	k += array[a];
	if(k > sum)
	{
		sum = k;
	}
	if(a == 4999)return;
	tansaku(a+1);
}
int main(void)
{
	while(1)
	{
		sum = 0;
		for(i=0;i<5000;i++)
		{
			array[i] = 0;
		}
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++)
		{
			scanf("%d",&array[i]);
		}
		for(i=0;i<n;i++)
		{
			tansaku(i);
			k = 0;
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(1){
        int n; cin >> n;
        if(n==0)break;
        int ans=-1e9;
        int now=0;
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin >> a[i];
            ans=max(ans,a[i]);
            if(now+a[i]>=0){
                now+=a[i];
                ans=max(ans,now);
            }else{
                now=max(0,a[i]);
            }
        }
        printf("%d\n",ans);
    }
}

C++: #include<iostream>
using namespace std;
int main(){
	int n=0,a[5000]={0},saidai=-100000;
	while(cin>>n&&n!=0){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;n>i;i++){
			int kazu=0;
			for(int x=0;x<=i;x++){
				kazu=a[i]+a[x+1];
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a,saidai=-100000;
	while(cin>>n&&n!=0){
		int a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;n>i;i++){
			for(int x=n;x>=i;x--){
				int kazu=0;
				for(int y=x;y>=i;y--){
					kazu=kazu+a[y];
				}
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}

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

int main(){
	int n, k;
	vector<int> dp;
	cin >> n;

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

		if(i == 0)
			dp.push_back(k);
		else
			dp.push_back(max(dp[i -1] + k, k));
	}
	int max = dp[0];
	for(int i = 0; i < n; i++){
		if(max < dp[i]){
			max = dp[i];
		}
	}
	cout << max << endl;
}

C++: #include <stdio.h>

int main(){
	int n;
	int buf[5000];
	long goukei;
	long max;
	
	int i,j;
	
	while(1){
		goukei = 0;
		max = -100001;
		scanf("%d",&n);
		if(n == 0)break;
		for(i = 0;i < n;i++){
			scanf("%d",&buf[i]);
		}
		
		for(i = 0;i < n;i++){
			goukei = 0;
			for(j = i;j < n;j++){
				goukei += buf[j];
				if(goukei > max){
					max = goukei;
				}
			}
		}
		
		printf("%ld\n",max);
	}
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int n;
int a[50001];
int S[50001];


int main(){

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

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

  int max = -100000;
  for (int i = 0; i < n + 1; ++i)
  {
    for (int k = 0; k < i + 1; ++k)
    {
      if(S[i] - S[k] > max) max = S[i] - S[k];
    }
  }

  cout << max << endl;

  }
}

C++: #include <iostream>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000001
#define IN_MAX 2147483647

using namespace std;
#define ll long long
#define dbg if(0)



int main(){
    while(true){
        int n,t;
        ll ans= - IN_MAX;
        cin>>n;
        if (n==0)break;

        ll rui[n+1];
        rui[0]=0;
        for(int i=1;i<=n;i++){
            cin >>rui[i];
            rui[i]+=rui[i-1];
            dbg cout <<rui[i]<<" ";
        }
        //次を見る
        //今までの最小値を更新したか？
        //したなら暫定解を確定しansと比較。最大値=最小値=発見した最小値にする
        //してなければ最大値の更新をする
        //見る場所が一番後ろまで行ったら終了。
        ll nmin=MAX,nmax=0;
        for(int i=0;i<=n;i++){
            if (rui[i]<nmin){
                ans=max(nmax-nmin,ans);
                nmax=rui[i];
                nmin=rui[i];
            }else{
                if(rui[i]>nmax){
                    nmax=rui[i];
                }
            }
            dbg cout <<nmax<<" "<<nmin<<endl;
        }
        ans=max(nmax-nmin,ans);
        dbg cout << endl;
        cout<<ans<<endl;
    }

    return 0;
}

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

int main(){
	int n, a;
	while(cin >> n, n){
		n++;
		vector<int> t(n);
		t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> a;
			t[i] = max(t[i-1]+a, a);
		}
		cout << *max_element(t.begin()+1, t.end()) << endl;
	}
	return 0; 
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define fst	first
#define scn second

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;

int main() {
	while (true) {
		int n;	cin >> n;
		if (n == 0)	break;
		vint a(n, 0);
		rep(i, n)	cin >> a[i];
		vector<ll> sum(n + 1, 0);
		rep(i, n)	sum[i + 1] = sum[i] + a[i];
		ll ret = -1e18;
		REP(i, n)	rep(j, i)	ret = max(ret, sum[i] - sum[j]);
		cout << ret << endl;
	}
	return 0;
}