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<string>
using namespace std;
int main(){
	int n,a[10000];
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int best=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			int count=0;
			for(int k=0;k<=i;k++){
				count+=a[j+k];
			}
			if(count>best)
				best=count;
		}
	}
	cout<<best<<endl;
	}
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    long 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>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

int main(){
	int n;
	while(scanf("%d",&n),n){
		int sum=0,ans=INT_MIN;
		rep(i,n){
			int t; scanf("%d",&t);
			sum += t;
			ans = max(ans,sum);
			if( sum<0 )sum=0;
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    int n = 0;
    while (cin>>n && n != 0) {
        int a[5001] = {};
        int max = -1000000;
        for (int i = 0; i < n; i++) {
            cin>>a[i];
            if (a[i] >= 0) {
                int temp = 0;
                for (int s = i; s >= 0; s--) {
                    temp += a[s];
                    if (temp > max) {
                        if (temp > max + a[i]) {
                            max = temp;
                            break;
                        }
                        max = temp;
                    }
                }
            }
        }
        cout<<max<<endl;
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

double dot(P a,P b){return real(conj(a)*b);};
double cross(P a,P b){return imag(conj(a)*b);};

int main(){
  int n;
  while(~scanf("%d",&n)){
    if(n==0)break;
    ll cur = 0;
    ll mx = 0;
    while(n--){
      ll x;
      cin>>x;
      cur = max(x,cur+x);
      mx = max(mx,cur);
    }
    cout<<mx<<endl;
  }
  return 0;
}

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

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

C++: 
#include<stdio.h>
#include <iostream>
#include<bits/stdc++.h> 

using namespace std;
int length=0;
int* sums;

int main(){
  string str="";
  while(1){
  cin>>length;
  if(length==0)break;
  sums=new int[length+1];
  sums[0]=0;
  int s=0;
  for(int i=0;i<length;i++){
    int v=0;
    cin>>v;
    s+=v;
    sums[i+1]=s;
  }
  int max=INT_MIN;
  for(int i=0;i<length+1;i++){
    for(int j=i;j<length+1;j++){
      int diff=sums[j]-sums[i];
      if(diff>max){
        max=diff;
      }
    }
  }
  cout<<max;
  cout<<"\n";
  }
  return 0;
}

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

int main() {
int n,b;
int a[5001];
while(1){
	cin>>n;
	if(n==0){
		break;
	}
	for (int kkk=1;kkk<=5001;kkk++){
		a[kkk]=0;
	}
	for (int kk=1;kk<=n;kk++){
		cin>>b;
		a[kk]=b;
	}
	int high=a[1];
	for (int k=1;k<=n;k++){
		for(int l=k;l<=n;l++){
			int sum=0;
			for(int m=k;m<=l;m++){
				sum=sum+a[m];
				if(sum>=high){
		high=sum;
			}
		}
	}
	
	}
cout<<high<<endl;
}
	return 0;
}

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

int main()
{

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

	while( 1 ) {

		int Max = -100001;

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

		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 - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

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

		res.push_back( Max );
		a.clear();
	
	}

	if( n != 0 ) {
		for( vector< long int > :: iterator mIt = res.begin(); mIt != res.end(); ++mIt ) {
			cout << *mIt << endl;
		}
	}

	return 0;

}

C++: #include<iostream>
#include<algorithm>
using namespace std;
long long dp[6000],n,a[6000],i,maxm;
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=1;i<=n;i++)cin>>a[i];
    dp[1]=maxm=a[1];
    for(int i=2;i<=n;i++){
      if(dp[i-1]>=0)dp[i]=dp[i-1]+a[i];
      else dp[i]=a[i];
      
      maxm=max(dp[i],maxm);
    }
    cout<<maxm<<endl;
  }
  return 0;
}

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

// warning: include *e
int getBackMaxSum(int* s, int *e) {
	int sum = *e, maxSum = sum;
	for (e--; s <= e; e--) {
		sum += *e;
		maxSum = max(sum, maxSum);
	}
	return maxSum;
}

int main () {
	while (cin >> n, n) {
		int a[n], maxSum = 0xffffffff;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			maxSum = max(maxSum, getBackMaxSum(a, a + i));
		}
		cout << maxSum << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main(){
	for (int n; cin >> n, n != 0; ) {
		vi a(n);
		rep(i, n) cin >> a[i];
		int ans = 0;
		rep(i, n) {
			int sum = 0;
			REP(j, i, n - 1) ans = max(ans, sum += a[j]);
		}
		cout << ans <<endl;
	}
	
	return 0;
}