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<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>

#include<vector>

#define INF 999999
using namespace std;
int main(){
    int N;
    while(cin>>N,N){
        int num[5500]={0},max=-INF;
        for(int i=0;i<N;i++){
            cin>>num[i];
        }
        for(int i=0;i<N;i++){
            int total=0;
            if(max<num[i])max=num[i];
            total+=num[i];
            for(int j=i+1;j<N;j++){
                total+=num[j];
                if(max<total)max=total;
            }
        }
        cout<<max<<endl;
    }
    return 0;
}

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

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; 
			}
			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 <stdio.h>
#include<math.h>
using namespace std;

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

		int array[n];
		for(int i=0;i<n;i++)scanf("%d",&array[i]);
		maximum = -600000000;
		for(int k=0;k<n;k++){//?§????????????????
			for(int j=k;j<n;j++){ //??????????????????
				sum = 0;
				for(int p=k;p<=j;p++){	//??????????????????
					sum += array[p];
				}
				maximum = (maximum >= sum)? maximum:sum;
			}
		}
		printf("%d\n",maximum);
	}

    return 0;
}

C++: #include<iostream>
using namespace std;
bool same(int a,int b){
  if(a*b>=0) return true;
  return false;
}
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int d;
    int s[n];
    int count = 0,begin = 0;
    int ans = -100000000;
    for(int i=0;i<n;i++){
      cin >> d;
      if(i==0) s[0] = d;
      else if(same(d,s[count])) s[count] += d;
      //cout << same(d,s[count]) << endl;
      else{
	count++;
	s[count] = d;
      }     
    }
    //for(int i=0;i<=count;i++) cout << s[i] << endl;
    if(s[0]<0) begin = 1;
    for(int i=begin;i<=count;i+=2){
      int h = s[i];
      if(ans<h) ans = h;
      for(int j=i+1;j<=count;j++){
	h += s[j];
	if(ans<h) ans = h;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int a[5001];
int main(){
    int n;
    while(cin >> n && n){
        rep(i, n) cin >> a[i];
        int ans = -INF;
        REP(i, 0, n){
            int sum = a[i];
            REP(j, i + 1, n){
                sum += a[j];
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<int> a(n);
		for(int i=0; i<n; i++){
			cin >> a[i];
		}
		
		int ans=-inf;
		for(int i=0; i<n; i++){
			int sum=0;
			for(int j=0; i+j<n; j++){
				sum += a[i+j];
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int64_t a[5000];
int64_t dp[2][5000];

int64_t solve(int n){
  int64_t summax=INT64_MIN;
  for(int i=0;i<n;i++){
    if(summax < a[i]){
      summax = a[i];
    }
  }

  for(int i=1;i<n;i++){
    for(int j=0;j<n-i;j++){
      dp[i%2][j] = dp[(i-1)%2][j] + a[i+j];

      if(summax < dp[i%2][j]){
        summax = dp[i%2][j];
      }
    }
  }
  return summax;
}

int main(){
  int64_t n;
  while(cin >> n,n!=0){

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

    cout << solve(n) << endl;
  }
  return 0;
}

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

int main(void){
  int n, input;
  long sum, max;
  while(cin >> n, n != 0){
    cin >> input;
    max = sum = input;
    for(int i = 0; i < n - 1; i++){
      cin >> input;
      if( sum < 0 )
	sum = input;
      else
	sum += input;
      if( max < sum )
	max = sum;
    }
    cout << max << endl;
  }
  return 0;
}

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[6000];

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=-1000000000000000000;
		rep(i,n) a[i]=0;
		
		int cou=0;
		rep(i,n){
			cou++;
			cin>>a[0];
			if(a[0]!=0){
				break;
			}
			
		}
		n-=cou;
		rep(i,n){
			int t;
			cin>>t;
			if(a[c]*t<0){
				a[++c]=t;
			}
			else a[c]+=t;
		}
		
		
		c++;
		//rep(i,c) cout<<i<<" "<<a[i]<<endl;
		
		//rep(i,c) cin>>a[i];
		MAX=a[0];
		rep(i,c){
			ll sum=0;
			for(int j=i;j<c;j++){
				sum+=a[j];
				MAX=max(MAX,sum);
			}
		}
		
		
		
		/*
		for(int i=1;i<=c;i++){
			rep(j,c+1-i){
				MAX=max(MAX,sum(j,i));
			}
		}
		*/
		cout<<MAX<<endl;
	}
	return 0;
}

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

int main(){

	int n;
	while (std::cin >> n, n){

		int max = 0, before;
		std::cin >> before;

		for (int i = 1, a; i < n; i++){
			std::cin >> a;
			before = std::max(before + a, a);
			max = std::max(max, before);
		}

		std::cout << max << std::endl;
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long int n, m[5001] = { 0 }, max = -2147483647, temp = 0, k;
	while (cin>> n && n!=0){
		for (int i = 0; i < n; i++){
			cin >> m[i];
		}
		for (int i = 0; i < n; i++){
			temp = m[i];
			for (int l = i + 1; l < n; l++){
				temp += m[l];
				if (temp > m[i]) if (max < temp) max = temp;
				else if (max < m[i]) max = m[i];
			}temp = 0;
		}
		cout << max << endl;
		max = -2147483647;
	}
	return 0;
}