Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

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

int main()
{
    int n;
    while(cin >> n && n)
    {
        int buf[5001]={};
        int max_sum = INT_MIN;

        /* store input values */
        for(int i=0; i<n; i++)
        {
            cin >> buf[i];
        }
        /* calc maximum sum */
        for(int i=0; i<n; i++)
        {
            int sum = 0;
            for(int j=i; j<n; j++)
            {
                sum += buf[j];
                if(sum > max_sum)
                {
                    max_sum = sum;
                }
            }
            
        }
        cout << max_sum << endl;
    }
    return 0;
}

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

int main(){
  int i,j,n,tmp,ans,a[5000];

  while(scanf("%d",&n) && n){
    for(i=0;i<n;i++)scanf("%d",&a[i]);
    
    ans = a[0];
    for(i=0;i<n;i++){
      for(j=i;j<n;j++){
	if(i==j)tmp = 0;
	tmp += a[j];
	ans = max(tmp,ans);
      }
    }
    printf("%d\n",ans);
  }
}

C++: #include <iostream>
using namespace std;
int main(void){

	int n, max=0;
	int *a;
	int sum;

	do{
		max = 0;
		//cout << endl;
		cin >> n;

		if (n == 0) break;

		a = new int[n];

		sum = 0;

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

			sum = 0;

			cin >> a[i];

			for (int j = i; j >= 0; j--){

				sum += a[j];
				if (max < sum) max = sum;
			}
		}

		cout << max << endl;
	} while (1);
}

C++: // start 20:09
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

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

using namespace std;

/*
メモ化
[開始インデックス][終了インデックス] = 合計値
*/

vector<vector<int> > memo(5000, vector<int>(5000, 0));

int sum(vector<int> &nums, int oft, int len) {
    int ret = 0;
    for ( int i = oft; i < len; i++ ) {
        // if ( memo[oft+i][oft+len] ) {
        //     return ret + memo[oft+i][oft+len];
        // }
        ret += nums[oft+i];
        // memo[oft+i][oft+len] = ret;
    }
    return ret;
}

int main() {
    int n;
    
    while(cin >> n, n) {
        int max_n = 0;
        vector<int> nums(n);

        REP(i, n) cin >> nums[i];
        
        REP(oft, n) REP(len, n-oft) {
            max_n = max(max_n, sum(nums, oft, len));
        }
        cout << max_n << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) break;
    int a[n];
    REP(i, n) cin >> a[i];
    int sum[n + 1];
    sum[0] = 0;
    REP(i, n) sum[i + 1] = sum[i] + a[i];
    int ans = -1e9;
    REP1(i, n) REP(j, i) ans = max(ans, sum[i] - sum[j]);
    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main() {
	int a,i,j,k,n,max,sum;
	vector<int> s;
	while (cin >> n) {
		if (n == 0)break;
		s.clear();
		max = 0;
		for (i = 0; i < n; i++) {
			cin >> a;
			s.push_back(a);
		}
		for (j = 0; j < n; j++) {
			sum = 0;
			for (k = j; k < n; k++) {
				sum += s[k];
				if (sum > max)max = sum;
			}
		}
		cout << max << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <climits>
using namespace std;
#define rep2(i,from,to) for(int i=(from); i<(to); ++(i))
#define rep(i,to) rep2(i,0,to)
int main() {
	int n;
	while(cin >> n && n) {
		int a[5001];
		int Max = INT_MIN;
		rep(i,n) {
			cin >> a[i]; 
		}
		rep(i,n) {
			int sum = 0;
			sum += a[i];
			rep2(j,i+1,n) {
				sum += a[j];
				Max = max(Max, sum);
			}
		}
		cout << Max << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int Merge(vector<int>& A, int p)
{
	while (p > 1 && A[p] > 0){
		int a = A[p - 2] + A[p - 1] + A[p];
		if ((a >= A[p - 2]) && (a >= A[p])){
			A[p - 2] += A[p - 1] + A[p];
			A[p - 1] = A[p] = 0;
			p -= 2;
		}
		else break;
	}
	return p;
}
int main()
{
	int n, k, p, m;
	bool isPlus = true;
	while (cin >> n){
		if (0 == n) break;
		vector<int> A(n, 0);
		m = INT_MIN;
		p = 0;
		for (int i = 0; i < n; ++i){
			cin >> k;
			if (m < k) m = k;
			if (0 == i){
				A[p] = k;
				isPlus = (k > 0);
			}
			else {
				if (isPlus == (k > 0)){
					A[p] += k;
				}
				else{
					if (isPlus){
						p = Merge(A, p);
						if (m < A[p]) m = A[p];
					}
					++p;
					A[p] = k;
					isPlus = !isPlus;
				}
			}
		}
		p = Merge(A, p);
		if (m < A[p]) m = A[p];
		cout << m << "\n";
	}
	return 0;
}

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

int main()
{
	int n=1, count = 0;
	int a[10000];
	while (n != 0) {
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = -10000;
		for (int ai = 0; ai < n - 1; ai++) {
			sum = 0;
			for (int bi = ai; bi < n; bi++) {
				sum = sum + a[bi];
				if (sum > max) {
					max = sum;
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    while(1){
        ll n; cin >> n;
        if(!n) break;
        vl a(n); rep(i,n) cin >> a[i];
        ll s = 0;
        ll ans = -linf;
        rep(i,n){
            s = max(s + a[i], a[i]);
            chmax(ans, s);
        }
        cout << ans << endl;
    }
}