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>
using namespace std;

typedef long long ll;
const ll INF = 10000000000;

int main()
{
	ll t, n;
	while( 1 )
	{
		scanf("%lld", &t);
		if(t == 0) break;

		ll c_max = -INF;
		ll c_min = 0;
		ll c_sum = 0;
		for(int i=0; i<t; i++)
		{
			scanf("%lld", &n);
			c_sum += n;
			if(c_min > c_sum) c_min = c_sum;
			if(c_max < c_sum - c_min) c_max = c_sum - c_min;
		}
		printf("%lld\n", c_max);
	}
}

C++: // AOJ 0022
#include <cstdio>
#include <cstring>

int main(void)
{
    int n;
    int num[5001];
    int sum;
    int max;
    
    while (scanf("%d", &n)){
        if (n == 0) break;
        
        memset(num, 0, 5001);
        for (int i = 0; i < n; i++){
            scanf("%d", &num[i]);
        }
        max = num[0];
        
        for (int i = 0; i < n; i++){
            sum = 0;
            for (int j = i; j < n; j++){
                sum += num[j];
                if (max < sum) max = sum;
            }
        }
        
        printf("%d\n", max);
    }
}

C++: #include <stdio.h>
int main()
{
	int n,a[5000];
	while(scanf("%d",&n)!=EOF){
		int max=-10001;
		if(n==0)
			break;
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				if(max<sum)
					max=sum;
			}
		}
		printf("%d\n",max);
	}
	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 = 0;
		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 <iostream>

#define SIZE 5001

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}

		int list[SIZE], max = -114514;
		list[0] = 0;
		for (int i = 0; i < n; i++) {
			cin >> list[i + 1];

			if (list[i + 1] > max) {
				max = list[i + 1];
			}
			list[i + 1] += list[i];
		}

		for (int i = 2; i <= n; i++) {
			for (int j = i; j <= n; j++) {
				if (list[j] - list[j - i] > max) {
					max = list[j] - list[j - i];
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a[5000],i,j,sum=0,max[5000]={-10001},c=0,n;
	
	while(1){
		scanf("%d",&n);
		if( n == 0)
			break;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				sum = sum + a[j];
				if(max[c] < sum)
					max[c] = sum;
			}
			sum = 0;
		}
		c++;
	}
	for(i=0;i<c;i++){
		printf("%d\n",max[i]);
	}
	return 0;
}

C++: #include<stdio.h>

int main()
{
	int n;
	for(;;)
	{
		scanf("%d",&n);
		if(n==0){return 0;}
		
		if( n >= 1 && n <= 5000){
		int a[5000]={0},max=0;
		for(int x=0;x<n;x++)
		{
			scanf("%d",&a[x]);

			for(int y=0;y<=x;y++)
			{
				if(y!=x)
				{
					a[y]+=a[x];
				}
				if(max<a[y])
				{
					max=a[y];
				}
			}
		}
		printf("%d\n",max);
		}
	}
}

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

 int main()
 {
     while(1){
         int n;
         cin >> n;
         if( !n ) break;

         int a;
         int max = numeric_limits<int>::min();
         int sum = numeric_limits<int>::min();
         for(int i=0; i<n; i++){
             cin >> a;

             if( max<0 && a<0 && max<a ) { max = a; continue; }
             else if( max<0 && a<0 && max>a){ continue; }

             if( a>0 ){
                 if( sum<0 ) sum = a;
                 else sum += a;
             }else{
                 if( sum+a>0 ) sum += a;
                 else sum = a;
             }
             if( sum > max ) max = sum;
         }
         cout << max << endl;
    }

    return 0;
}

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

using namespace std;
int n,a[5008];

int solve(){
  int res=0;
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      int tmp=0;
      for(int p=i;p<=j;p++){
        tmp+=a[p];
      }
      res=max(res,tmp);
    }
  }
  return res;
}

int main(){
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
    }

    printf("%d\n",solve());

  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int n;

constexpr long long minf = -100000 * 5000;

void solve(){
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    vector<ll> sum(n+10,0);    // sum[i] = a[0] + ... + a[i-1]
    for(int i=0;i<n;i++) sum[i+1] = sum[i] + a[i]; 

    ll ans = minf-10;

    rep(i,n) rep(j,n) if(i<=j){
        // k = a[i] + ... + a[j]
        ll k = sum[j+1] - sum[i];
        ans = max(ans,k);
    }

    cout << ans << endl;
}

int main(){
    while(cin>>n){
        if(n==0) break;
        solve();
    }
}

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

int main()
{
	int n;
	while (cin >> n&&n > 0) {
		int a, maxsum = 0;
		for (int i = 0;i < n;++i) {
			cin >> a;
			if (a > 0) {
				maxsum += a;
			}
		}
		cout << maxsum << endl;
	}
}

C++: #include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    vector<int> a;
    a.resize(n+1);
    a[0]=0;
    REP(i,n) cin >> a[i+1];
    REP(i,n) a[i+1]+=a[i];
    int answer=-1048576;
    REP(i,n)REP(j,i) answer=max(answer,a[i]-a[j]);
    cout << answer << endl;
  }
}