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<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<stack>
#include<set>
#include<cmath>

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

#define EPS 1e-6

using namespace std;

int main(){

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

   vector<int>v;
   int s=0;
   v.push_back(s);

   rep(i,n){
   cin >> a;
   s+=a;
   v.push_back(s);
   }

   int vmin=0; int vmax=0;
   rep(i,n+1){
   if(v[i]<vmin) vmin=v[i];
   if(v[i]>vmax) vmax=v[i];

   }

	cout << vmax-vmin << endl;

   }

	return 0;
}

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

using namespace std;

int main(void){
	int Max, Num = 0, In;
	while (true){
		vector<int>	Dat;
		Max = -100000;
		cin >> Num;
		if (Num == 0)break;
		for (int i = 0; i < Num; i++){
			cin >> In;
			Dat.push_back(In);
		}
		for (int i = 1; i < Num; i++){
			Dat[i] = max(Dat[i], Dat[i - 1] + Dat[i]);
			Max = max(Max, Dat[i]);
		}
		cout << Max << endl;
	}
	return 0;
}

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

using namespace std;

int main(void){
	
	int n,j,sum,max1;
		
	while(cin>>n,n){
		
		vector<int> v;
		
		for(int i=0;i<n;i++){
			cin>>j;
			v.push_back(j);
		}
		max1=v[0];

		for(int i=0;i<n;i++){
				sum=0;
			for(int j=i;j<n;j++){
				sum=sum+v[j];
				max1=max(max1,sum);
			}
		}
		cout<<max1<<endl;
		

	}
}

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

int main()
{

	int n, num;
	vector< int > a;
	vector< int > res;

	while( 1 ) {

		int Max = -100000;

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

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

		res.push_back( Max );
		a.clear();
	
	}

	for( vector< int > :: iterator mIt = res.begin(); mIt != res.end(); ++mIt ) {
		cout << *mIt << endl;
	}

	return 0;

}

C++: #include <bits/stdc++.h>

using namespace std;

long maxSubArray(long arr[], int n)
{
	long maximum = arr[0];
	long currentMaximum = arr[0];
	long sum;
	for(int i = 1; i < n; i++) {
		sum = currentMaximum + arr[i];
		currentMaximum = max(arr[i], sum);
		maximum = max(maximum, currentMaximum);
	}
	return maximum;
}




int main()
{
	//freopen("input.txt", "r", stdin);
	long n;
	while(scanf("%ld", &n) == 1 && n != 0) {
		long arr[200001];
		for(int i = 0; i < n; i++) {
			cin >> arr[i];
		}

		cout << maxSubArray(arr, n) << endl;
	}

	return 0;
}

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

int main(){
	int n;
	
	while(cin>>n,n){
		int max=0;
		int sum[n];
		for(int i=0;i<n;i++){
			int num;
			cin>>num;			
			sum[i]=num;
			for(int j=0;j<i;j++){sum[j]+=num;if(max<sum[j])max=sum[j];}
		}
		cout<<max<<endl;
	}
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int A[5010];
int n;
int main()
{
  while(scanf("%d",&n)){
    if(n ==0)
      break;
  for(int i = 0;i < n;i++){
    cin>>A[i];
  }
  int ans = -(1<<25);
  for(int i = 0;i < n;i++){
    int sum = 0;
    for(int j = i;j <n;j++){
      sum +=A[j];
      ans =max(sum,ans);
    }
  }
  cout <<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int num;
    int input[5001];

    while (cin >> num) {
        if (!num)
            break;

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

        int sum_max = input[0];
        for (int i = 0; i < num; i++) {
            int tmp = 0;
            for (int j = i; j < num; j++) {
                tmp += input[j];
                
                sum_max = max(tmp, sum_max);
            }
        }
        cout << sum_max << endl;
    }

    return 0;
}

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

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

C++: #include<bits/stdc++.h>
using namespace std;
int num[5000];
int  serch(int line,int now,int maxe)
{
    if(maxe==now)return line;
    return max(line,serch(line+num[now],now+1,maxe));
}
int main()
{
    int n;
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>num[i];
        int ans=num[0];
        for(int i=0;i<n;i++)ans=max(serch(num[i],i+1,n),ans);
        cout<<ans<<endl;
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<int>in(n);
    rep(i,n)cin>>in[i];
    int max=in[0];
    rep(i,n){
      int sum=0;
      loop(j,i,n){
	sum+=in[j];
	if(max<sum)max=sum;
      }
    }
    cout<<max<<endl;
  }


}

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

using namespace std;

int main(){
  vector<int> sum;
  int n;
  int input;

  while(cin>>n){
    if(n==0)break;
    vector<int> array;
    for(int i=0;i<n;i++){
      cin>>input;
      array.push_back(input);
    }
    vector<int> now;
    for(int i=0;i<n;i++){
      int a=0;
      for(int j=0;j<=i;j++){
	a+=array[j];
      }
      now.push_back(a);
    }
    int ma=0;
    for(int i=0;i<n;i++){
      if(i<n-1){
	ma=max(now[i],now[i+1]);
      }
    }
    sum.push_back(ma);
  }
  vector<int> ans;
  int i=0;
  int size=sum.size();
  while(!sum.empty()){
    ans.push_back(sum[size-1-i]);
    sum.pop_back();
    i++;
  }
  i=0;
  while(!ans.empty()){
    cout<<ans[size-1-i]<<"\n";
    ans.pop_back();
  }
  return 0;
}