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 <algorithm>
using namespace std;
int main()
{
	int n,a[5000];
	while(1){
		int maxa=-10001;
		scanf("%d",&n);
		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];
				maxa=max(maxa,sum);
			}
		}
		printf("%d\n",maxa);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll a[5001];

int main() {
  int num;
  while( cin >> num, num ) {
    ll maxn = 0;
    for ( int i = 0; i < num; i++ ) cin >> a[i];
    for ( int i = 0; i < num; i++ ) {
      ll sum = 0;
      for ( int j = i; j < num; j++ ) {
	sum += a[j];
	maxn = max(maxn,sum);
      }
    }
    cout << maxn << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int dp[n][n];
    vector<int>a(n);
    int ans=-2000000000;
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++){
      cin>>a[i];
      for(int j=0;j<=i;j++){
	if(j!=i){
	  dp[j][i]+=a[i]+dp[j][i-1];
	}else{
	  dp[j][i]=a[i];
	}
	ans=max(ans,dp[j][i]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int sum[5001] = {};
	while (cin >> n, n)
	{
		//累積和の配列を作る
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			sum[i + 1] = sum[i] + a;
		}

		//さっき作った配列の中から最大値を選ぶ
		int ret = sum[1];
		for (int i = 0; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				ret = max(ret, sum[j] - sum[i]);
			}
		}
		cout << ret << endl;
	}
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;

int main()
{
	int n;

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

		int sum = 0, input, maxer = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> input;
			sum += input;

			if (sum < 0)
				sum = 0;
			maxer = max(sum, maxer);
		}

		cout  <<  maxer << endl;
	}


	return 0;
}

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

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

C++: #include <algorithm>
#include <cstdio>
#include <deque>
#include <numeric>
#include <vector>

using namespace std;

template <typename C>
vector<int> compact(const C& container) {
  vector<int> compacten;
  int sign = 1;
  int acc = 0;
  for (auto n : container) {
    if (sign * n >= 0) {
      acc += n;
    } else {
      compacten.push_back(acc);
      acc = n;
      sign *= -1;
    }
  }
  compacten.push_back(acc);
  return compacten;
}

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

    deque<int> seq;
    for (int i = 0; i < n; ++i) {
      int x;
      scanf("%d", &x);
      seq.push_back(x);
    }
    while (seq.size() != 0 && seq.front() <= 0) { seq.pop_front(); }
    while (seq.size() != 0 && seq.back() <= 0) { seq.pop_back(); }

    auto compacten_seq = compact(seq);
    vector<int> partial_sums = { compacten_seq.back() };
    for (int i = compacten_seq.size() - 1; i > 0; i -= 2) {
      int s = partial_sums.back() + compacten_seq[i - 1];
      partial_sums.push_back(compacten_seq[i - 2] + (s < 0 ? 0 : s));
    }
    int max_sum = accumulate(
        partial_sums.begin(),
        partial_sums.end(),
        partial_sums.front(),
        [](int a, int b) { return max(a, b); });
    printf("%d\n", max_sum);
  }

  return 0;
}

C++: /* AOJ 0022*/

#include<iostream>
#include<queue>
using namespace std;

long int m;
int n;

void calc(int *data,int num,int sum){
	if(sum>=m){
		m=sum;
	}
	if(num==n){
		return;
	}
	else{
		calc(data,num+1,sum+data[num]);
	}
}

int main(){

	queue<int> ans;

	while(cin>>n){
		if(n==0){
			break;
		}
		int *data = new int[n];
		m=0;
		for(int i=0;i<n;i++){
			cin>>data[i];
		}

		for(int i=0;i<n;i++){
			calc(data,i,0);
		}
		ans.push(m);
	}

	int size=ans.size();
	for(int i=0;i<size;i++){
		cout<<ans.front()<<endl;
		ans.pop();
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//char ch;
//string S, T, U;
ll i, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, w, x, y, z,maxx=INT_MIN, minn=INT_MAX, ans=0;

int main()
{
    while(true)
    {
        scanf("%d",&n);
        if(n == 0)
        {
            break;
        }
        int A[n];
        forr(i,n)
        {
            scanf("%d",&A[i]);
        }
        int sum=0;
        int best=A[0];
        forr(i,n)
        {
            sum=max(A[i],sum+A[i]);
            best=max(best,sum);
        }
        printf("%d\n",best);
    }
     return 0;
}

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

int a[6000];
int n,ans;

void saiki(int num,int sum);

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

        for(int i = 0;i < n;i++) scanf("%d",&a[i]);

        for(int i = 0;i < n;i++) saiki(i,0);

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

    }
    return 0;
}

void saiki(int num,int sum)
{
    if(num + 1 > n)
    {
        printf("num = %d n = %d\n",num,n);
        return;
    }
    sum += a[num];
    if(sum > ans) ans = sum;
    saiki(num+1,sum);
}