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>
using namespace std;
int main(){
    int n,sum,t,i;
    while(cin>>n&&n){
        sum=0;
        for(i=0;i<n;i++){cin>>t;sum+=t;}
        cout<<sum<<endl;
    }
}

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

int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0) break;
    int i,cr,max;
    cr=max=0;
    while(n--){
      cin>>i;
      cr +=i;
      if(cr<0) cr=0;
      if(cr>max) max=cr;
    }
    cout<<max<<endl;
  }
  return 0;
}

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <class Monoid> struct SegmentTree{
    using Func = function<Monoid(Monoid, Monoid)>;

    int size;
    vector<Monoid> seg;
    const Func merge;
    const Monoid def;

    SegmentTree(int n, Monoid d, const Func f): merge(f), def(d){
        for(size = 1; size <= n; size <<= 1);
        seg.assign(size*2, def);
    }

    Monoid& operator[] (int i) { return seg[i+size]; };
    void build(){ for(int i = size-1;i >= 0;i--) seg[i] = merge(seg[i*2], seg[i*2+1]); } 

    void update(int i, Monoid val){
        seg[i += size] = val;
        while(i >>= 1) seg[i] = merge(seg[i*2], seg[i*2+1]);
    }

    void add(int i, Monoid val){ update(i, val+seg[i+size]); }

    Monoid get(int a, int b){
        Monoid l = def, r = def;
        for(a += size, b += size; a < b; a >>= 1, b >>= 1){
            if(a & 1) l = merge(l, seg[a++]);
            if(b & 1) r = merge(seg[--b], r);
        }
        return merge(l, r);
    }
};

int solve(int n);

struct Data{
	int l;
	int r;
	int sum;
	int ma;
	bool t;
	Data(): l(0), r(0), sum(0), ma(0), t(true){}
	Data(int a){
		l = a;
		r = a;
		sum = a;
		ma = a;
		t = false;
	}

};


signed main(){
	int n;

	while(cin >> n, n != 0){
		solve(n);
	}

	return 0;
}

int solve(int n){

	auto merge = [](Data a, Data b){
		if(b.t) return a;
		if(a.t) return b;
		Data c;
		c.l = max(a.l, a.sum + b.l);
		c.r = max(b.r, b.sum + a.r);
		c.sum = a.sum + b.sum;
		c.ma = max({a.ma, b.ma, a.r + b.l});
		c.t = false;
		return c;
	};

	SegmentTree<Data> seg(n, Data(), merge);

	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		seg[i] = Data(a);
	}
	seg.build();
	cout << seg.get(0, n).ma << endl; 

	return 0;
}

C++: #include <iostream>
#include <algorithm>
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++: #include<iostream>
using namespace std;
int main(){
	int n,i,max,a[100000],p,q,pre;
	while(cin>>n,n){
		i=0;
		max=-1000000000;
		while(i!=n)
			cin>>a[i++];
		for(p=0;p<n;p++){
			pre=0;
			for(q=p;q<n;q++){
				pre+=a[q];
				if(pre>max)
					max=pre;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
using namespace std;

int main(){
	int N;
	while(cin >> N && N > 0){
		int a[N];
		REP(i,N){
			cin >> a[i];
		}

		int maximum = a[0];
        REP(i,N){
            int sum = 0;
            int maximum_i = 0;
            for(int j = i; j < N; j++){
					sum += a[j];
                    maximum_i = max(sum,maximum_i);
            }
            maximum = max(maximum,maximum_i);
		}
		cout << maximum << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <algorithm>
#include <cctype>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);

ll n,ans;
vector<ll> dp,num;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		ans=-inf;
		dp=vector<ll>(n);
		num=vector<ll>(n);
		for(int i=0;i<n;i++) cin>>num[i];
		dp[0]=num[0];
		for(int i=0;i<n-1;i++) dp[i+1]=max(num[i+1],num[i+1]+dp[i]);
		for(int i=0;i<n;i++) ans=max(ans,dp[i]);
		cout<<ans<<endl;
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;


int main(){
    int n;
    while(cin>>n && n){
        vector<int> v(n);
        int ans=0;
        rep(i,0,n){
            int sum=0;
            rep(j,i,n){
                sum+=v[j];
            }
            ans=max(ans,sum);
        }
        cout<<ans<<endl;
    }
    
    
    
    
    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;
ll dp[5000];
int main(){
	memset(dp,0, sizeof(dp));
	//ll dp[5000];
	int n,a;
	while(1){cin >> n;if(!n)break;
		ll ans=0;
		
		rep(i,n){cin>>a;
			if(dp[i-1]>0)dp[i]=dp[i-1]+a;
			else dp[i] = a;
			ans = max(ans,dp[i]);
		}
		cout<<dp[-1]<<endl;
	}

}

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

int main(){
	int n, k = 0;
	int a[5000];
	long long int b[1000] = {0}, c[1000] = {0};
	while(cin >> n){
		if(n == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> a[i];
			b[k] = b[k]+a[i];
			if(b[k] < 0){
				b[k] = 0;
			}
			if(b[k] > c[k]){
				c[k] = b[k];
			}
		}
		if(c[k] == 0){
			sort(a,a+n);
			c[k] = a[n-1];
		}
		k++;
	}
	for(int i = 0; i < k; i++){
		cout << c[i] << endl;
	}
}

C++: #include <iostream>

#define max(X,Y) ((X > Y)?X:Y)

int main(void)
{
	while(true)
	{
		int n;
		int m=0,prev=0;
		std::cin >> n;
		if(!n)
			break;

		prev = -1000001;
		for(int i=0; i<n; i++)
		{
			int a;
			std::cin >> a;
			prev = max( a, prev + a );
			m = max( m, prev );
		}
		std::cout << m << std::endl;
	}
	return 0;
}