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 <cassert>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>

int solve(std::istream& in, int n)
{
    std::vector<int> all(n);
    std::vector<int> koho;
    int temp = 0;
    int max = 0;
    for(int i = 0; i < n; ++i) {
        in >> all[i];
        if(temp && all[i] < 0){
            koho.push_back(temp);
            if(temp + all[i] < 0){
                temp = 0;
            }else{
                temp += all[i];
            }
        }else
        if(all[i] > 0){
            temp += all[i];
        }
    }
    if(temp) koho.push_back(temp);
    if(koho.empty()) return *std::max_element(all.begin(), all.end());
    return *std::max_element(koho.begin(), koho.end());
}
int main()
{
    int n;
    std::cin >> n;
    while(n){
        std::cout << solve(std::cin, n) << std::endl;
        std::cin >> n;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define INF -100000000000000
int main(void){
    int n,a,max=INF;
    while(std::cin>>n){
        if(n==0) break;
        std::vector<int> dp(n+1);
        dp[0]=INF;
        for(int i=0;i<n;i++){
            std::cin>>a;
            dp[i+1]=(a>0?dp[i]+a:a);
            max=std::max(max,dp[i+1]);
        }
        std::cout<<max<<std::endl;
    
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

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

int main(void){  
  int n;
  while(cin>>n,n){
    int sum = 0, maxs = 0, a;
    REP(i,n){
      cin >> a;
      if(a>=0)
        sum += a;
      else{
        maxs = max(sum, maxs);
        sum = 0;
      }
    }
    cout << maxs << endl;
  }
  return 0;
}

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

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {

		int Max = -1000000;

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

		//??????????????????
		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 - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

			if ( a[i] > Max ) {
				Max = a[i];
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

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

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

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

    num = 0;

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

  return 0;
}

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

C++: #include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
int main() {
  int n, input;
  vector<int> input_v;
  vector<int> part_v;
  int max_num = 0;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    input_v.clear();
    while(n--) {
      cin >> input;
      input_v.push_back(input);
    }
    max_num = 0;
    for (int i = 0; i < input_v.size(); ++i) {
      for (int len = 3; len <= input_v.size() - i; ++len) {
        part_v.clear();
        for (int m = 0; m < len && i + m < input_v.size(); ++m) {
          part_v.push_back(input_v[i + m]);
        }
        max_num = max(accumulate(part_v.begin(), part_v.end(), 0), max_num);
      }
    }
    cout << max_num << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,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=0;x<=i+1;x++){
				kazu=a[i]+a[x+1];
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}

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

int main(){
        int n, a[5010],b[5010];
        while(cin >> n && n){
                for(int i=0; i<n; i++) cin >> a[i];
                b[0] = 0;
                for(int i=1; i<n+1; i++){
                        b[i] = b[i-1] + a[i-1];
                } 
                int max=0;
                for(int r=1; r<n+1; r++){
                        for(int i=0; i<n-r+1; i++){
                                int x = b[r+i] - b[i];
                                max = (max > x)? max : x;
                        }
                }
                cout << max << endl;
        }
}

C++: 7
-5
-1
6
4
9
-6
-7
13
1
2
3
2
-2
-1
1
2
3
2
1
-2
1
3
1000
-200
201
1
-1
0

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n,x[5001],sum=0,maxx=0,c=0;
        cin>>n;
        c=n;
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            cin>>x[i];
        }
        for(int i=0;i<n;i++){
            c--;
            //for(int j=i;j<n;j++){
            //    for(int c=n-1;c>=i;c--){
                    for(int z=i;z<=c;z++){
                        sum+=x[z];
                        maxx=max(maxx,sum);
                    }
                    sum=0;
              //  }
            //}
        }
        cout<<maxx<<endl;
    }
}

C++: #include <iostream>
using namespace std;
int main() {
	int s,h,n,i,a[5000];
	while(true) {
		cin >> n;
		if (n==0) break;
		for (i=0;i<n;i++) cin >> a[i];
		s=0; h=-100000;
		for (i=0;i<n;i++) {
			s=(s+a[i]>=a[i]) ? s+a[i] : a[i];
			h=(s > h)  ? s : h;
		}
        cout << h << endl;
	}
	return 0;
	}

C++: #include<stdio.h>

int main()
{
	int n;
	while(true)
	{
		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]);
			if(a[x]<=10000||a[x]>=-100000)
			{
				x--;
			}
			else
			{
			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 <climits>
using namespace std;
int s[5010];
int main(){
  int n, a;
  while(cin >> n, n){
    int ans = -(INT_MAX-1);
    for(int i = 0 ; i < n ; i++){
      cin >> a;
      if(!i)s[i] = a;
      else{
	s[i] = max(a, a + s[i-1]);
      }
      ans = max(ans, s[i]);
    }
    cout << ans << endl;
  }
  return 0;
}