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 <limits.h>
using namespace std;
int main()
{
	int n, k, p = 0;
	bool isPlus = true;
	while (cin >> n){
		if (0 == n) break;
		vector<int> A(n, 0);
		int m = INT_MIN;
		for (int i = 0; i < n; ++i){
			cin >> k;
			if (0 == i){
				A[p] = k;
				isPlus = (k > 0);
			} else {
				if (isPlus == (k > 0)){
					A[p] += k;
				} else{
					while (0 != p){
						if (m < A[p - 1]) m = A[p - 1];
						if (m < A[p]) m = A[p];
						if (A[p - 1] + A[p] >= 0){
							A[p - 1] += A[p];
							--p;
							isPlus = true;
						}else break;
					}
					if (isPlus == (k > 0)){
						A[p] += k;
					}else{
						if (m < A[p]) m = A[p];
						++p;
						A[p] = k;
						isPlus = !isPlus;
					}
				}
			}
		}
		if (m < A[p]) m = A[p];
		cout << m << "\n";
		for (int i = 0; i <= p; ++i) A[p] = 0;
	}
	return 0;
}

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

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

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

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

int main() {
	int n;
	while (std::cin >> n) {
		if (n == 0) break;
		std::vector<int> a;
		int max = 0, left = 0, right = 0, lmin = 0, rmin = 0;
		for (int i = 0; i < n; ++i) {
			int ai;
			std::cin >> ai;
			a.push_back(ai);
			max += ai;
		}
		// ここをかく
		std::vector<int>::iterator leftend = a.begin();
		for (std::vector<int>::iterator itr = a.begin(); itr != a.end(); ++itr) {
			left += *itr;
			if (left < lmin) {
				lmin = left;
				leftend = itr;
			}
		}
		for (std::vector<int>::iterator itr = a.end() - 1; itr != leftend; --itr) {
			right += *itr;
			if (right < rmin) {
				rmin = right;
			}
		}
		max = max - lmin - rmin;
		std::cout << max << std::endl;
	}

	return 0;
}

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

using namespace std;

int N;
long long K[5001],T;

int main()
{
        scanf("%d",&N);
        if (N == 0) return 0;

        T = 0;
        K[0] = 0;

        for (int i=1;i<=N;i++){
                scanf("%lld",K+i);
        }

        for (int i=1;i<=N;i++) {
                K[i] += K[i-1];
        }

        for (int i=0;i<=N;i++) {
                for (int j=i;j<=N;j++) {
                        T = max(T,K[j]-K[i]);
                }
        }

        printf("%lld\n",T);

        main();
}

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

using namespace std;

#define FOR(a) for(int i = 0; i < a; i++)
#define FORR(a, b) for(int i = a; i < b; i++)

int main(void){
	int Max, Num = -1, In;
	while (Num != 0){
		vector<int>	Dat;
		Max = -100002;
		cin >> Num;
		Dat.push_back(-100001);
		FOR(Num){
			cin >> In;
			Dat.push_back(In);
		}
		FORR(1, Num + 1){
			Dat[i] = max(Dat[i], Dat[i - 1] + Dat[i]);
			Max = max(Max, Dat[i]);
		}
		cout << Max << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,s,a;
	while(cin>>n,n){
		cin>>a;
		m=s=a;n--;
		while(n--){
			cin>>a;
			if(s<0)s=a;
			else s+=a;
			m=max(s,m);
		}
		cout<<m<<endl;
	}
}

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

int main(){
	int n, sum, result;
	while(cin >> n){
		if(n == 0) break;
		vector<int> array;
		for(int i=0; i<n; i++){
			int t;
			cin >> t;
			array.push_back(t);
		}
		result = array[0];
		for(int i=0; i<n; i++){
			sum = 0;
			for(int j=i; j<n; j++){
				sum += array[j];
				result = max(result, sum);
			}
		}
		cout << result << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
while (1){
long n,dset[5000],temp=0,MINEdset[5000],max=-1100000,h[5000],b=0;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                MINEdset[j]=temp;
        }
        for (int j=i;j<n;j++){
                if (max<MINEdset[j]){
                        max=MINEdset[j];
                }
        }
        h[b]=max;
        max=-1100000;
        b++;
        temp=0;
}
max=-1100000;
for (int i=0;i<=b;i++){
        if (max<h[i]){
                max=h[i];
        }
}
cout<<max<<endl;
}
return 0;
}

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

using namespace std;

#define int long long
#define pii pair<int,int>

const int MaxN=100*1000+10;
int arr[MaxN];
int ps[MaxN];

int findRightSticky(int s,int e){
	int mx=arr[e];
	int ind=e;
	for (int i=s;i<=e;++i)
		if (mx<ps[e]-ps[i-1]){
			mx=ps[e]-ps[i-1];
			ind=i;
		}
	return ind;
}

int findLeftSticky(int s,int e){
	int mx=arr[s];
	int ind=s;
	for (int i=s;i<=e;++i)
		if (mx<ps[i]-ps[s-1]){
			mx=ps[i]-ps[s-1];
			ind=i;
		}
	return ind;
}

pair<int,int> findMaxSubarray(int s,int e){
	if (s==e)
		return make_pair(s,s);
	int mid=(s+e)/2;
	pii mxsubleft=findMaxSubarray(s,mid);
	pii mxsubright=findMaxSubarray(mid+1,e);
	int mxstickyleft=findRightSticky(s,mid);
	int mxstickyright=findLeftSticky(mid+1,e);
	int totalmx=max(ps[mxstickyright]-ps[mxstickyleft-1],max(ps[mxsubleft.second]-ps[mxsubleft.first-1],ps[mxsubright.second]-ps[mxsubright.first-1]));
	if (totalmx==ps[mxsubleft.second]-ps[mxsubleft.first-1])
		return mxsubleft;
	else if (totalmx==ps[mxsubright.second]-ps[mxsubright.first-1])
		return mxsubright;
	else
		return make_pair(mxstickyleft,mxstickyright);
}

int32_t main(){
	int n;
	cin >> n;
	while(n){
		for (int i=1;i<=n;++i){
			cin >> arr[i];
			ps[i]=ps[i-1]+arr[i];
		}
		pii prd=findMaxSubarray(1,n);
		cout << ps[prd.second]-ps[prd.first-1] << endl;
		cin >> n;
	}
	// cout << prd.first-1 << " " << prd.second-1 << endl;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <numeric>	// require accumulate
#include <climits>

using namespace std;

int main()
{
	string str = "";
	int n;

	while (1){
		getline (cin, str );
		stringstream ssn(str);
		ssn >> n;

		if (n == 0){
			break;
		} // end if

		vector <int> a(n + 1, 0 );
		vector <int> sum (n + 1, 0 );
		int i,j;

		for (i = 1; i <= n; ++i){
			getline (cin, str );
			stringstream ss(str);
			ss >> a[i];
		} // end for

		for (i = 1; i <= n; ++i){
			sum[i] = accumulate (a.begin(), a.begin() + i + 1, 0 );
		} // end for

		int maxn = INT_MIN;
		for (i = 1; i <= n; ++i){
			for (j = i; j <= n; ++j){
				 maxn = max (maxn , sum[j] - sum[i - 1] );
			} // end for
		} // end for

		cout << maxn << endl;			

	} // end while

	return 0;
}