Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

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

long long int sum(const std::vector<int> &a, int begin, int end){
	long long int s = 0;
	for(int i=begin; i<end; i++){
		s += a[i];
	}
	return s;
}

int main() {
	int n;
	std::vector<int> a;
	while(std::cin >> n, n){
		for(;n--;){
			int ai;
			std::cin >> ai;
			a.push_back(ai);
		}
		long long int max_sum = sum(a, 0, a.size());
		for(int len = a.size() - 1; len--;){
			for(int begin = 0; begin < a.size() - len + 1; begin++){
				if(begin && a[begin-1] > 0)
					continue;
				if(a[begin+len] > 0)
					continue;
				long long int s = sum(a, begin, begin + len);
				if(s > max_sum){
					max_sum = s;
				}
			}
		}
		std::cout << max_sum << std::endl;
		a.clear();
	}
	return 0;
}

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+1, 0);
    int sum = 0;
    for(int i=0; i<n; i++){
      int tmp;
      cin >> tmp;
      sum += tmp;
      a[i+1] += sum;
    }

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

  }

  return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;
int main(void)
{
    int n, a[500];
    while (1) {
        cin >> n;
        if (n == 0)
            break;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        int goukei = 0, led = -10000000;
        for (int i = 1; i <= n; i++)
        {
            goukei = 0;
            for (int j = i; j <= n; j++)
            {
                goukei = goukei + a[j];
                led = max(goukei, led);
            }
        }
        cout << led << endl;
    }
    return 0;
}

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

using namespace std;

int debug = 0;

int main(void){
	int n, m, i, j, k;
	int tmp, max;
	vector<int> intv;

	while(cin >> n){
		if(n == 0){
			break;
		}else{
			//ÇÝÝ
			for(i=0;i<n;i++){
				cin >> m;
				intv.push_back(m);
				//if(debug) cout << "int[" << i << "] =" << intv[i] << endl; 
			}

			//vfð¸ç·
			tmp=0;
			for(i=1;i<intv.size();i++){
				if(intv[tmp] > 0){
					if(intv[i] > 0){ //¯Èç
						intv[tmp] += intv[i];
						intv[i] = 0;
					}else{ //ÙÈç
						tmp = i;
					}
				}else if(intv[tmp] < 0){
					if(intv[i] < 0){
						intv[tmp] += intv[i];
						intv[i] = 0;
					}else{
						tmp = i;
					}
				}
			}
			/*
			if(debug){
				for(i=0;i<intv.size();i++){
					cout << intv[i] <<endl;
				}
				cout << "----------------------" << endl;
			}
			*/
			intv.erase( remove(intv.begin(), intv.end(), 0), intv.end());
			/*
			if(debug){
				for(i=0;i<intv.size();i++){
					cout << intv[i] <<endl;
				}
			}
			*/

			max = 0;
			int vsize = intv.size();
			for(i=1;i<=vsize;i++){//i:Â
				//if(debug) cout << "number =" << i << endl;
				for(j=0;j<=vsize-1-i+1;j++){ //j:JnÊu
					tmp = 0;
					for(k=0;k<i;k++){
						tmp += intv[j+k];
					}
					//if(debug) cout << "tmp ==" << tmp << endl;
					if(max <= tmp){
						max = tmp;
					}
				}
			}
			cout << max << endl;
			intv.clear();
		}
	}
	return 0;
}

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

int main(){
  vector<int> v,s(10001);
  int a,b,n,o=0;
  while(cin>>b){
    fill(s.begin(),s.end(),0);
    o =0;
    if(b==0) break;
    else{
    for(int i=0;i<b;i++){
      cin>>a;
      v.push_back(a);
    }
    for(int i = 0; i < b; i++){
      int sum = 0;
      for(int j = i; j < b; j++){
	sum += v[j];
	s.push_back(sum);
      }
    } 


  int d = *max_element(s.begin(),s.end());
  cout<<d<<endl;
    }
    s.clear(),v.clear();
  }
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#define EPS 1e-10
#define INF (-(1<<21))
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (1) {
		cin >> n;
		if (!n)break;
		vector<int>a(n);
		for (int i = 0; i < n; i++)cin >> a[i];
		int tmp;
		int m = INF;
		for (int i = 0; i < n; i++) {
			tmp = 0;
			for (int j = i; j < n; j++) {
				tmp += a[j];
				m = max(m, tmp);

			}
		}
		cout << m << endl;
	}
	return 0;
}

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

using namespace std;
static const int MAXV = 5000;

int main() {
  while(1) {
    int n;
    long long data[MAXV], max=0, sum=0;
    scanf("%d", &n);
    if (n==0) break;
    for(int i=0; i<n; i++) scanf("%lld", &data[i]);
    for (int i=0; i<n; i++) {
      for (int j=i; j<n; j++) {
	sum+=data[j];
	if(max<sum) max=sum;
      }
      sum=0;
    }
    printf("%lld", max);
  }
}

C++: #include <iostream>
#include <climits>
#include <numeric>
int main()
{
  while (1) {
    int n;
    std::cin >> n;
    if (n == 0) break;
    int max = -INT_MAX;
    int a[n];
    for (int i = 0;i < n; i++) {
      std::cin >> a[i];
    }
    for (int i  = 0; i < n; i++) {
      if (i < 0) continue;
      for (int j = i + 1; j <= n; j++) {
        int temp = std::accumulate(a + i, a + j, 0);
        if (temp > max) max = temp;
      }
    }
    std::cout << max << std::endl;
  }
}

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

int main(){
  int n, num, a, maxx;

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

    num = maxx = 0;

    for(int i=0;i<n;i++){
      cin >> a;
      num += a;
      if(num<0) num = 0;
      maxx = max(maxx,num);
    }

    cout << maxx << endl;
  }

  return 0;
}

C++: /*
 * AOJ-Volume0-0022
 */
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

typedef long long ll;

/*
 * Find maximum sum.
 *   array: number list
 */
int findMaximumSum(vector<int> &array){
  int sumValue = array[0];
  int maxValue = INT_MIN;
  int length = array.size();

  for(int i = 1; i < length; i++){
    int value = array[i];

    if(sumValue < 0){
      sumValue = value;
    }else{
      sumValue += value;
    }

    if(maxValue < sumValue){
      maxValue = sumValue;
    }
  }

  return maxValue;
}

void solve(int n){
  vector<int> a(n);

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

  printf("%d\n", findMaximumSum(a));
}

int main(){
  int n;

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

    solve(n);
  }

  return 0;
}

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

int main(){
	int n, k = 0;
	int a[5000];
	long long int b[1000] = {0}, c[1000] = {0};
	while(cin >> n){
		if(n == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> a[i];
			b[k] = b[k]+a[i];
			if(b[k] < 0){
				b[k] = 0;
			}
			if(b[k] > c[k]){
				c[k] = b[k];
			}
		}
		k++;
	}
	for(int i = 0; i < k; i++){
		cout << c[i] << endl;
	}
}

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

int main()
{

	int n, num;
	vector< int > a;

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

		int Max = -100001;

		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] = max( a[i], a[i] + a[i - 1] );
			Max  = max( Max, a[i] );
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}