Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

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

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

using namespace std;

int main(){
	while(true) {
		long long int n, tmp;
	cin >> n;
	if (n<=0) {
		//cout << 0 << endl;
		return 0;
	}
	vector<long long int> intervalos;
	intervalos.reserve(n);
	cin >> tmp;
	bool esNegativo = tmp < 0;
	intervalos.push_back(tmp);
	for (int i = 1; i < n; ++i){
		cin >> tmp;
		if (esNegativo == tmp < 0){
			intervalos.back() += tmp;
		} else {
			intervalos.push_back(tmp);
			esNegativo ^= true;
		}
	}
	long long int best = 0;
	long long int current = 0;
	for (int i = 0; i < intervalos.size(); ++i){
		if (intervalos[i]+current <= 0) {
			current = 0;
		} else {
			current+=intervalos[i];
			if (current > best) {
				best=current;
			}
		}
	}
	intervalos.clear();
	cout << best << endl;
	}
	
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#define li long int
using namespace std;

int main()
{
  li n,a;
  li i,j;
  li b[5005]={};

  while(1){
    priority_queue<li> pq;
    cin>>n;
    if(n==0)break;
    for(i=1;i<=n;i++){
      cin>>a;
      b[i]=b[i-1]+a;
      for(j=i;j>=0;j--)
	pq.push(b[i]-b[j]);
    }
    cout<<pq.top()<<endl;
  }
}

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

using namespace std;

int main(){
	int n;
	int a[5000] = { 0 };

	while (cin >> n, n){
		int ans = -100000;
		for (int i = 0; i < n; i++){
			cin >> a[i];
		}
		for (int i = 0; i < n; i++){
			int sum = 0;
			for (int j = 0; (i + j < n); j++){
				sum += a[i + j];
				ans = max(sum, ans);
			}
		}
		cout << ans << endl;
	}

	return 0;

}

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

int main(){

  int n,count,maxu;

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

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

    for(int i=n-1;0<=i;i--){
      for(int j=0;i+j<n;j++){
	count = 0;
	for(int k=j;k<=j+i;k++)
	  count += numbers[k];
	maxu = max(maxu,count);
      }
    }
    cout << maxu << endl;

  }

  return 0;
}

C++: /**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0022&lang=jp
 */
#include <stdio.h>
#define N 5000

int getsign(int d){
	return d >= 0 ? 1 : -1;
}

int seqsum(int n){
	int a[N];
	int b[N];
	int c = 0;
	int s = 0;

	scanf("%d", a);
	b[0] = a[0];
	s = getsign(a[0]);

	for(int i=1; i<n; ++i){
		scanf("%d", a+i);
		if(s == getsign(a[i])){
			b[c] += a[i];
		}else{
			b[++c] = a[i];
			s = getsign(a[i]);
		}
	}

	int m = b[0];
	int sum = m;
	if(c == 0){
		if(m >= 0){ return m; }
		m = a[0];
		for(int i=1; i<n; ++i){
			if(m < a[i]){
				m = a[i];
			}
		}
		return m;
	}

	a[0] = b[0];
	m = a[0];
	for(int i=1; i<=c; ++i){
		a[i] = a[i-1] < 0 ? b[i] : a[i-1] + b[i];
		if(m < a[i]){
			m = a[i];
		}
	}

	//for(int i=1; i<=c; ++i){
	//	if(m < sum + b[i]){
	//		sum += b[i];
	//		m = sum;
	//	}else if(m < b[i]){
	//		sum = m = b[i];
	//	}else{
	//		sum += b[i];
	//	}
	//}

	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>
using namespace std;
int main(){
    int n=0,a[5000]={0},saidai=-100000;
    while(cin>>n&&n!=0){
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;n>i;i++){
            int kazu=0;
            for(int x=i;x<n;x++){
                kazu=kazu+a[x];
                cout<<kazu<<endl;
                if(kazu>saidai){
                    saidai=kazu;
                }
            }
        }
        cout<<saidai<<endl;
    }
}