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++: //0022 Maximum Sum Sequece

//2<=n<=5000ÂÌñ©çA×Ú·éÌaÌÅålð¦æ
//È¨AÌlÍ-10`10ÌÍÍÅ é
//KÉâÁ½ç°i(1¨n-1){i*(n-i)}ñÅ]TÅlÞ©
//Æè ¦¸Ag¤ñÌÉV½ÉÁíÁ½àÌð«µÄAÁ¦éàÌðø­ûjÅ¢¢©


#include<iostream>
#include<algorithm>
#include<numeric>
#include<climits>
using namespace std;

int main(void)
{
	const int N = 5000;
	int n;
	while(cin >> n, n)
	{
		int i, j;
		int a[N];
		int sum, max_sum = INT_MIN;

		for(i = 0; i < n; i++)
			cin >> a[i];

		//iÂÌðg¤
		for(i = 1; i <= n; i++)
		{
			//Ü¸ÍAÜÆÜÁÄg¤ªÌaðvZµÄ¨­
			sum = accumulate(a, a+i, 0);
			max_sum = max(sum, max_sum);

			for(j = 0; j+i < n; j++)
			{
				//ÌÂðg¢Ü·
				sum -= a[j];
				sum += a[j+i];
				max_sum = max(max_sum, sum);
			}
		}

		cout << max_sum << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long

using namespace std;
const int MOD=1000000007;
const int INF=9000000009;
const double eps=1e-10;

signed main(){
  int n;
  while(cin>>n,n){
    vector<int> a(n+100);
    REP(i,n){
      int x;cin>>x;
      a[i+1]=a[i]+x;
    }
    int ans=-INF;
    REP(i,n+1)LOOP(j,i+1,n+1)ans=max(ans,a[j]-a[i]);
    cout<<ans<<endl;
  }
  return 0;
}

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

#define MAX_N 5000

int main(){
    int n, ans = 0, in, before;
    while(std::cin >> n, n){
        std::cin >> before;
        ans = before;
        for(int i = 1; i < n; ++i){
            std::cin >> in;
            before = std::max(in, before + in);
            ans = std::max(before, ans);
        }
        std::cout << ans << std::endl;
        ans = 0, before = 0;
    }
    return 0;
}

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

int main(){
	int i, j, k, n, sum, result;
	int a[5000];
	while(cin >> n){
		if(n == 0){
			break;
		}
		result = 0;
		for (i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (i = 0; i < n; i++) {
			for (j = 1; j <= n-i; j++) {
				sum = 0;
				for (k = 0; k < j; k++) {
					sum += a[i+k];
				}
				if(result < sum){
					result = sum;
				}
			}
		}
		cout << result << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int count,max,i,j,k,l;
   int sum,data_set[5000];
  while(cin>>count){
    if(!count)break;
    cin>>data_set[0];
    max=data_set[0];
    for( i=1;i<count;i++){
      cin>>data_set[i];
    }
    //  for(l=1;l<=count;l++){
      for( j=0;j<count;j++){
	sum=0;
	for( k=j;k<count;k++){
	  sum+=data_set[k];
	if(max<sum)max=sum;
	}
    }
    cout<<max<<endl;
  }
}

C++: #include<iostream>
main(){int n,v[5000],m;while(std::cin>>n,m=n){for(;m--;)std::cin>>v[m];m=*v;for(int i=0;i<n;i++)for(int j=i,k=v[i];j++<n;k+=v[j])m=k>m?k:m;std::cout<<m<<'\n';}}

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

using namespace std;

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

int main(void){
	int Max, Num = -1, In, N = 0;
	vector<int>	Dat;
	while (Num != 0){
		Max = -100000;
		cin >> Num;
		Dat.push_back(-100000);
		FOR(Num){
			cin >> In;
			Dat.push_back(In);
		}
		FORR(1, Num + 1){
			Dat[i] = max(Dat[i], Dat[i - 1] + Dat[i]);
			Max = max(Max, Dat[i]);
		}
		N = Dat.max_size();
		FOR(N){
			Dat.pop_back();
		}
		cout << Max << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algortihm>
using namespace std;
int main(){
	long int n, m[5001] = { 0 }, max = -2147483647, temp = 0, k;
	while (cin>> n && n!=0){
		for (int i = 0; i < n; i++){
			cin >> m[i];
		}
		for (int i = 0; i < n; i++){
			temp = m[i];
			for (int l = i + 1; l < n; l++){
				temp += m[l];
				if (temp > m[i]) if (max < temp) max = temp;
				else if (max < m[i]) max = m[i];
			}temp = 0;
		}
		cout << max << endl;
		max = -2147483647;
	}
	return 0;
}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <cstring>

using namespace std;

int main(){
	int n;
	int max,tmpmax1,tmpmax2;
	while(cin >> n && n != 0){
		max = -100001;
		int *factor = new int[n];
		
		for(int i = 0; i < n; i++){
			cin >> factor[i];
		}

		for(int i = 0; i < n; i++){
			tmpmax1 = 0;
			tmpmax2 = -100001;
			for(int j = i; j < n; j++){
				tmpmax1 += factor[j];
				if(tmpmax2 < tmpmax1){
					tmpmax2 = tmpmax1;
				}
			}
			if(tmpmax2 < 0){
				for(int i = 0; i < n; i++){
					if(tmpmax2 == factor[i]){
						if(i != n - 1 && factor[i + 1] < 0){
							tmpmax2 += factor[i + 1];
							break;
						}
						break;
					}
				}
			}
			if(max < tmpmax2){
				max = tmpmax2;
			}
		}
		delete [] factor;
		cout << max << endl;
	}
	
	return 0;
}

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()
{
    while(true) {
        int n;
        vi v;
        cin >> n;
        if(n==0) break;

        while(n--) {
            int tmp;
            cin >> tmp;
            v.push_back(tmp);
        }
        vi w(v);
        rep(i, v.size()) v[i] = max(v[i-1] + v[i], v[i]);
        P(*max_element(ALL(v)));
    }
    return 0;
}