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 <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


int n;
ll a[5000];

ll sum(int i,int j){
	ll s=0;
	rep(k,j){
		s+=a[i+k];
	}
	return s;
}

int main(){
	while(cin>>n,n!=0){
		int c=0;
		ll MAX=-100000000;
		rep(i,n) a[i]=0;
		cin>>a[0];
		rep(i,n-1) cin>>a[i+1];
		c=n-1;
		/*
		rep(i,n-1){
			int t;
			cin>>t;
			if(a[c]*t<0){
				a[++c]=t;
			}
			else a[c]+=t;
		}
		*/
		for(int i=1;i<=c+1;i++){
			rep(j,c+1-i){
				MAX=max(MAX,sum(j,i));
			}
		}
		cout<<MAX<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n;

	while (1)
	{
		int a[5001] = {0}, s[5001] = {0}, max;

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

		for (int i=1; i<=n; i++)	//入力
			cin >> a[i];

		for (int i=1; i<=n; i++) {
			for (int j=1; j<=i; j++) {
				s[i] += a[j];		//s[i] = a[1]+a[2]+...+a[i]
			}
		}

		max = s[1];

		//int cont = 0;	//Debug
		for (int i=1; i<=n; i++) {
			for (int j=1; j<=i; j++) {
				//if (max < s[i] - s[j-1]) cout << j << '-' << i << ", max = " << s[i] - s[j-1] << endl;	//Debug
				max = (max < s[i] - s[j-1]) ? s[i] - s[j-1] : max;	//区間i,jの和を求めて比較
				//cont++;	//Debug
			}
		}

		cout << max << endl;
		//cout << cont << endl;
	}

	return 0;
}

C++: #include <stdio.h>

int main(void) {
  while( 1 ) {
  long long n, ans = 0, now = 0, i;
  scanf("%lld", &n);
  if(!n) break;
  int a[n];
  for(i = 0; i < n; ++i) scanf("%d", &a[i]);
  for(i = 0; i < n; ++i) {
    now += a[i];
    if(now > ans) ans = now;
    if(now < 0) now = 0;
  }
  if(!ans) {
    int max = -1000000;
    for(i = 0; i < n; ++i) if(max < a[i]) max = a[i];
    ans = max;
  }
  printf("%lld\n", ans);
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#define INF 1<<27
using namespace std;
int main(){
  int n;
  while(cin >> n,n) {
    int sum[5000] = {0},a[5000];
    for(int i = 0 ; i < n ; i++ ) {
      cin >> a[i];
      if(i == 0) sum[i] += a[i];
      else  sum[i] += a[i] + sum[i-1];

    }
    int mx = sum[0];
    for(int i = 0 ; i < n-1 ; i++ ){
      for(int j = i+1 ; j < n ; j++ ){
	mx = max(mx,max(sum[j] - sum[i],sum[j]));
      }
    }
    cout << mx << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
        vi v(n+1,0);
        rep(i,n)cin>>v[i];
        ll ans=0;
        for(int i=0;i<n;i++){
            ll temp=0;
            for(int j=i;j<n;j++){
            for(int k=i; k<=j;k++)temp+=v[k];
            ans=max(ans,temp);
                temp=0;
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
#include<numeric>
using namespace std;


int main(void) {

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

    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];

    vector<int> dp(n+5, 0);
    for(int i=1; i<=n; i++){
      dp[i] = max( a[i-1], dp[i-1] + a[i-1] );
    }
    int ans = dp[1];
    for(int i=1; i<=n; i++){
      ans = max(ans, dp[i]);
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n;
  while(true){
    cin>>n;
    if(!n)break;
    int seq[n];
    for(int i=0;i<n;i++)
      cin>>seq[i];
    int max = 0;
    for(int i=0;i<n;i++){
	int sum = 0;
      for(int j=i;j<n;j++){
	  sum+=seq[j];
	if(sum>max)max = sum;
      }
    }
    cout << max << endl;
  }
  return 0;
}

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

vector<int> num;

int main(void){
  while(true){
    int maximum = 0, n;
    cin >> n;
    if(!n)  break;
    num.clear();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < num.size(); i++){
      int sum = num[i];
      for(int j = i + 1; j < num.size(); j++){
        sum += num[j];
        if(sum > maximum) maximum = sum;
      }
      if(num[i] > maximum) maximum = num[i];
    }
    cout << maximum << endl;
  }
  return 0;
}

C++: int a[5001];
int b[5001];
int c[5001];
int d[5001];

int main() {return 0;}

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

int main()
{
	int number,*values;
	
	while(cin >> number)
	{
		if(number == 0) break;

		values = new int[number];
		int max = -100001;

		for(int i = 0 ; i< number ;i++)
		{
			cin >> values[i];
		}

		for(int i = 0;i<number ; i++)
		{
			int sum = 0;
			for( int j = i; j < number ;j++)
			{
				sum += values[j];
				if(max < sum)
				{
					max = sum;
				}
			}
		}

		cout << max << endl;
	}

	delete [] values;

	return 0;
}

C++: #include <iostream>

using namespace std;
int main(){
  int n;
  int num[10000];
  while( cin >> n,n ){
    int max = -100001;

    for(int i = 0 ; i < n ; i++)cin >> num[i];

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

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

int main(){
	int n, k;
	vector<int> dp;
	while(true){
		cin >> n;
		if(n == 0)
			return 0;
		for(int i = 0; i < n; i++){
			cin >> k;
			if(i == 0)
				dp.push_back(k);
			else
				dp.push_back(max(dp[i -1] + k, k));
		}
		int max = dp[0];
		for(int i = 0; i < n; i++){
			if(max < dp[i]){
				max = dp[i];
			}
		}
		dp.clear();
		cout << max << endl;
	}
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
int main() {
	int n, a[5001], rui[5002] = { 0 };
	while (1) {
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
			rui[i + 1] = rui[i] + a[i];
		}
		int max = -100001;
		for (int i = 0; i <= n; ++i) {
			for (int j = i; j <= n; ++j) {
				if (rui[j] - rui[i] > max) {
					max = rui[j] - rui[i];
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}