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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
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();}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#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())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const double INF = 1e12;

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

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){
      for(int k = 1;k < n;++k){
        res = a[i];
        for(int j = i+1;j<i+1+k;++j){
          if(j>n)break;
          res +=a[j];
        }
        ans = max(ans,res);
        res = 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main()
{
   int n;
   int a[5000];
   int maxsum=0;
   cin>>n;
   for(int i=0;i<n;++i){
      cin>>a[i];
      if(a[i]>0){
         maxsum+=a[i];
      }
   cout<<maxsum<<endl;
}

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

int main()
{

	int n, num;
	vector< long int > a;

	while( 1 ) {

		int Max = -1000001;

		cin >> n;
		if( n == 0 ) break;

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		//?????§???
		for( int i = 1; i < n; i++ ) {
		
			a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

			if ( a[i] > Max ) {
				Max = a[i];
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}
*/

#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;
	
	}

	return 0;

}

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

int main () {

int n = -1, max = 0, cum;


    cin >> n;
    int *foo = new int [n];


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

        cin >> foo [i];

        if (i == 0)
            max = foo [i];

        cum += foo[i];

        if (cum < 0)
            cum = 0;

        if (cum > max && cum > 0)
            max = cum;

        }

    cout << endl;
    cout << max << endl;






    return 0;

}

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

using namespace std;

int main()
{
  long long int n, a[5001], t, s;

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

    for(int i = 0; i < n; i++){
      s = a[i];
      t = max(t, s);
      for(int j = i+1; j < n; j++){
	t = max(t, s+a[j]);
	s += a[j];
      }
    }

    cout << t << endl;
  }

  return 0;
}

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

int main() {
  int x,n;
  int a[5000];
  long int sum,nextsum;
  while(cin >> n) {
    if(n == 0) break;
    for(int i=0;i<n;i++) {
      cin >> x;
      a[i] = x;
    }
    /*  for(int j=0;j<n;j++) {
        for(int i=j+1;j<n;i++) {
        for(int m=0;m<i-j;m++) {
        sum[k] += a[j+m];
        }
        k++;
        }
        }
        cout << *max_element(sum,sum+k) << endl;
    */
    //全パターン生成はむり
    sum = 0;
    for(int i=0;i<n;i++) {
      if(a[i] >= 0) {
        nextsum = a[i];
        for(int j=1;j<n-i;j++) {
          nextsum += a[i+j];
          if(nextsum > sum)
            sum = nextsum;
        }
      }

    }
    cout << sum << endl;
  }
}

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

int main() {
	int n;
	while (cin >> n, n) {
		int k[5003];
		for (int i = 0;i < n;i++)cin >> k[i];

		int dp[5002];
		dp[0] = 0;
		for (int i = 1;i <= n;i++) {
			dp[i] = max(dp[i - 1] + k[i - 1], k[i - 1]);
		}

		int ans = -1800000000;
		for (int i = 1;i <= n;i++)ans = max(ans, dp[i]);
		cout << ans << endl;
	}
	return 0;
}