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 <bits/stdc++.h>
using namespace std;

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll n, a;
  while (true) {
    cin >> n;
    if (n == 0) return 0;
    vector<ll> dp(n, -INFL);
    cin >> dp[0];  // n番目に切った時の最大値
    for (int i = 0; i < n - 1; i++) {
      cin >> a;
      dp[i + 1] = max(dp[i] + a, a);
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
  }
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    int a[5000],sum[5001];
    sum[0]=0;
    for(int i=0;i<n;i++){
      cin>>a[i];
      sum[i+1]=sum[i]+a[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<=n;j++){
        ans=max(ans,sum[j]-sum[i]);
      }
    }
    cout<<ans<<endl;
  }
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;

int main()
{
	int n;

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

		int sum = 0, input, maxer = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> input;
			sum += input;
			maxer = max(sum, maxer);
		}

		cout << maxer << endl;
	}


	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)

using namespace std;

int main(void){
	long int n , a[5005] , s[5005] , m;
	while (cin >> n && n){
		REP(i,n){
			cin >> a[i];
		}
		s[0] = 0;
		FOR(i,1,n){
			s[i] = s[i-1]+a[i-1];
		}
		m=-100000;
		REP(i,n){
			FOR(j,i+1,n+1){
				if(s[j]-s[i]>m)
					m=s[j]-s[i];
			}
		}
		cout << m << endl;
	}


	return 0;
}

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

using namespace std;
int length=0;
int* sums;

int main(){
  label:
  cin>>length;
  if(length==0)return 0;
  sums=new int[length];
  
  int s=0;
  for(int i=0;i<length;i++){
    int v=0;
    cin>>v;
    s+=v;
    sums[i]=s;
  }
  int max=INT_MIN;
  for(int i=0;i<length;i++){
    for(int j=i+1;j<length;j++){
      int diff=sums[j]-sums[i];
      if(diff>max){
        max=diff;
      }
    }
  }
  cout<<max;
  cout<<"\n";
  goto label;
  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main (){
while (1){
long n,dset[5000],max=-99999,temp=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];
                if (max<temp){
                        max=temp;
                }
        }
temp=0;
}
printf ("%d\n",max);
}
return 0;
}

C++: #include <stdio.h>
#define mx(a,b) (a<b?b:a)
int main() {long long i,j,k,n,f;while (scanf("%lld",&n)!=EOF && n) {j=i=0,f=-5000000007;while (n--) {scanf("%lld",&k);f=mx(f,k);j+=k;i=mx(i,j);j=mx(j,0);} if (f<=0 && !i) i=f;printf("%lld\n",i);} return 0;}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int n, num[5010];

int mina(int a, int b) {
	if (a < b) return a;
	return b;
}

int main() {
	cin >> n;
	while (n != 0) {
		int sum = 0;
		int maxsum = 0;
		int minmax = -100001;
		for (int i = 0; i < n; i++) {
			cin >> num[i];
			sum += num[i];
			if (sum < 0) sum = 0;
			if (num[i] >= 0) minmax = 100000*5000+1;
			if (num[i] < 0 && num[i] > minmax) minmax = num[i];
			if (sum > maxsum) maxsum = sum;
		}
		cout << mina(maxsum, minmax) << endl;

		cin >> n;
	}

	return 0;
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@*/
/*@                       @*/
/*@ debug output erased ? @*/
/*@                       @*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@*/

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int mod=1000000007;
    int n;
    int ans;
    for (;;) {
        scanf("%d",&n);
        if (n!=0) {
            vector<int> p(n);
            for (auto&e:p) {
                scanf("%d",&e);
            }
            ans=p[0];
            for (int i=0;i<n;i++) {
                int tmp=0;
                for (int j=i;j<n;j++) {
                    tmp+=p[j];
                    ans=max(ans,tmp);
                }
            }
        } else {
            break;
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#define INF 1500000000

using namespace std;


int main(){
	int n;
	while(cin>>n && n){
		vector<int >data;
		data.push_back(0);
		for(int i=0;i<n;i++){
			int x;
			cin>>x;
			data.push_back(x+data.back());
		}
		int ans=-1*INF;
		for(int i=0;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				ans=max(ans,data[j]-data[i]);
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>

using namespace std;


int sumarray(int *array, int idx1, int idx2);


int main(){
  int n, Max, ibuf;
  int *List;

  //ifstream ifs("input.txt"); // for debug

  while(cin >> n){
    if(n == 0) break; // if n=0, end calc

    List = new int[n];  // allocate List

    for(int i=0; i<n; i++){
      cin >> List[i];
      //cout << List[i] << " "; // for debug
    }

    //cout << endl; // for debug

    Max = 0;
    for(int l=1; l<=n; l++){
      for(int i=0; i<=n-l; i++){
	ibuf = sumarray(List, i, i+l);
	if(ibuf > Max) Max = ibuf;
	//cout << ibuf << endl; // for debug
      }
    }

    cout << Max << endl;

    delete List; // deallocate List
  }

}


int sumarray(int *array, int idx1, int idx2){ // sum array[idx1] ~ array[idx2-1]
  int ret = 0;
  for(int i=idx1; i<idx2; i++){
    ret += array[i];
  }
  return ret;
}

C++: #include <iostream>
int main(){
	int n, v[5000], m;
	while(std::cin >> n, m=n){
		for(;m--;)std::cin >> v[m-1];

		m = *v;
		for(int i=0;i<n;i++)
			for(int j=i,k=v[i];j<n;j++,k+=v[j])
				m=k>m?k:m;

		std::cout << m << '\n';
	}	
}

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

using namespace std;

int main() {
  int n;
  vector<int> datas;
  vector<int> sums;

  while (cin >> n, n != 0) {
    int input;
    for (int n_i = 0; n_i < n; n_i++) {
      cin >> input;
      datas.push_back(input);
    }
    for (int data_i = 0; data_i < n-1; data_i++) {
      sums.push_back(datas[data_i]+datas[data_i+1]);
    }

    int max = *sums.begin();
    for (auto sum_i = sums.begin(); sum_i != sums.end(); sum_i++)
      if (max < *sum_i)
        max = *sum_i;
    cout << max << endl;
  }

  return 0;
}