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>

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

		m = 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;
}

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

int main() {
	int n, a;
	vector<int> an;
	vector<vector<int>> AN;
	while (cin >> n) {
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> a;
			an.push_back(a);
		}
		AN.push_back(an); an.clear();
	}

	for (int i = 0; i < AN.size(); i++) {
		long long int max = 0, MAX = 0 , counter = 0;
		for (int j = 0; j < AN[i].size(); j++) {
			if (AN[i][j] >= 0) {
				max += AN[i][j];
				if (MAX < max)MAX = max;
				counter = 1;
			}
			else {
				if (counter==1){
					if (AN[i][j] + max >= 0)max += AN[i][j];
					else {
						max = 0;
						counter = 0;
					}
				}
			}
		}
		cout << MAX << endl;
	}
	
	return 0;
}

C++: #include <stdio.h>
#define mx(a,b) (a<b?b:a)
int main() {long long i,j,k,n;while (scanf("%lld",&n)!=EOF && n) {j=i=0;while (n--) {scanf("%lld",&k);j+=k;i=mx(i,j);j=mx(j,0);} printf("%lld\n",i);} return 0;}

C++: #include <iostream>
#include <climits>
using namespace std;
int s[2];
int main(){
  int n, a;
  while(cin >> n, n){
    int ans = -(INT_MAX-1);
    for(int i = 0 ; i < n ; i++){
      cin >> a;
      if(i == 0)s[0] = a;
      else{
	s[1] = max(a, a + s[0]);
	s[0] = s[1];
      }
      ans = max(ans, s[0]);
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#define INF 1000000000
using namespace std;
int ary[5010],fn[80],ff[80],fl[80],fr[80];

int main(){
	int N;
	while(true){
		cin>>N;
		if(N==0) break;
		for(int i=0;i<N;i++){
			cin>>ary[i];
		}
		int NN=sqrt(N),NNN=(N-1)/NN+1,cnt,hog,hog2;
		for(int i=0;i<NNN;i++){
			hog=hog2=-INF;
			for(int j=NN*i;j<min(NN*(i+1),N);j++){
				for(int k=j;k<min(NN*(i+1),N);k++){
					cnt=0;
					for(int l=j;l<=k;l++){
						cnt+=ary[l];
					}
					hog=max(hog,cnt);
					if(k==min(N,NN*(i+1))-1) hog2=max(hog2,cnt);
					if(j==NN*i&&k==min(N,NN*(i+1))-1) ff[i]=cnt;
				}
				if(j==NN*i) fl[i]=hog;
			}
			fn[i]=hog;
			fr[i]=hog2;
		}
		int res=-INF;
		for(int i=0;i<NNN;i++){
			res=max(res,fn[i]);
			for(int j=i+1;j<NNN;j++){
				hog=0;
				cnt=fr[i]+fl[j];
				for(int k=i+1;k<j;k++){
					cnt+=ff[k];
				}
				res=max(res,cnt);
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int seqsum(int n){
	int a = 0;
	int b[5000];
	int c = 0;
	int s = true;
	scanf("%d", &a);
	b[0] = a;
	s = a > 0 ? 1 : -1;

	for(int i=1; i<n; ++i){
		scanf("%d", &a);
		if(s * a > 0){
			b[c] += a;
		}else{
			b[++c] = a;
			s = a > 0 ? 1 : -1;
		}
	}

	int m = b[0] < 0 ? 0 : b[0];
	int sum = m;
	for(int i=1; i<=c; ++i){
		if(sum < 0 && m < b[i]){
			sum = m = b[i];
		}else{
			sum += b[i];
			if(m < sum){
				m = sum;
			}
		}
	}
	return m;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}

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

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> num(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> num[i];
		}
		vector<int> memo(n);
		memo[0] = num[0];
		for(int i = 1; i < n; ++i)
		{
			if(memo[i - 1] + num[i] > num[i])
			{
				memo[i] = memo[i - 1] + num[i];
			}
			else
			{
				memo[i] = num[i];
			}
		}
		int max_num = -999999999;
		for(int i = 0; i < n; ++i)
		{
			if(max_num < memo[i])
			{
				max_num = memo[i];
			}
		}
		cout << max_num << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,math[5010],most,bell;
  while(1){
    cin >> n;
    if(n==0){
      break;
    }


    for(int i=0;i<n;i++){
      cin >> math[i];
    }
    most = math[0];
    for(int i=0;i<n;i++){
      bell=0;
      for(int j=i;j<n;j++){
	bell+=math[j];
	if(most<bell){
	  most=bell;
	}
      }
    }
    cout << most << endl;
  }
}

C++: #include <stdio.h>
#define MAX(x,y) x>y?x:y

int main(void)
{
  while(1){
    int n;
    scanf("%d", &n);
    if(n==0){
      break;
    }

    int a[5000];
    int max = 0;

    int i,j,k;
    for(i=0; i<n; ++i){
      scanf("%d", &a[i]);
      for(j=0; j<=i; ++j){
        int sum = 0;
        for(k=j; k<=i; ++k){
          sum += a[k];
        }
        if(max<sum){
          max = sum;
        }
      }
    }

    printf("%d\n", max);
  }

  return 0;
}

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

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

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

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int ans=0,seq=0;
    while(n--){
      int i;
      cin>>i;
      seq=max(seq+i,i);
      ans=max(ans,seq);
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,i,j;
  cin >> n;
  while(n!=0) {
    long long sum[5001]={};
    int b;
    long long o=1<<20;
    o*=-1;
    cin >> sum[1];
    for(i=2;i<=n;i++){
      cin >> b;
      sum[i]=sum[i-1]+b;
      //cout << sum[i] << endl;
    }
    
    for(i=0;i<=n;i++){
      for(j=i+1;j<=n;j++){
	o=max(o,sum[j]-sum[i]);
      }
    }
    cout << o << endl;
    cin >> n;
  }
  return 0;
  
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n && n)
	{

		vint v(n+1); v[0] = 0;
		rep(i, n)
			cin >> v[i+1];

		partial_sum(ALL(v), v.begin());

		int res = 0;

		rep(i, n) REP(j, i + 1, n + 1)
			chmax(res, v[j] - v[i]);

		cout << res << endl;
	}
}