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>

int main(){
  int n;
  int temp,max,a;

  while(1){
    std::cin >> n;
    if(n==0){
      break;
    }
    int a[n];
    for(int i=0;i<n;i++){
      std::cin >> a[i];
    }
    max = a[0];
    for(int i=0;i<n;i++){
      temp = a[i];
      for(int j=i+1;j<n;j++){
        temp += a[j];
        if(max < temp){
          max = temp;
        }
      }
    }
    std::cout << max << std::endl;
  }
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#define EPS 1e-10
#define INF (-(1<<21))
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (1) {
		cin >> n;
		if (!n)break;
		vector<vector<int> >v(n, vector<int>(n));
		vector<int>a(n);
		for (int i = 0; i < n; i++)cin >> a[i];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i == j)v[i][j] = a[i];
				else v[i][j] = INF;
			}
		}
		int max = INF;
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				if (i == j) {
					//cout << v[i][j] << " ";
					continue;
				}
				v[i][j] = v[i][j - 1] + a[j];
				if (max < v[i][j])max = v[i][j];
				//cout << v[i][j] << " ";
			}
			//cout << endl;
		}
		cout << max << endl;
	}
	return 0;
}

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

using namespace std;

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

int main() {
  
  int N;
  while(cin >> N && N) {
    vector<int> in(N), v(N);
    rep(i, N) cin >> in[i];
    int ans = -1<<29;
    rep(i, N) {      
      if(i-1 >= 0 && v[i-1] >= 0) {
	v[i] += v[i-1] + in[i];
      }
      else {
	v[i] = in[i];
      }
      ans = max(ans, v[i]);
    }
    cout << ans << endl;
  }
  
  return 0;
}

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

using namespace std;

int main()
{
	int n;

	while (scanf("%d", &n), n) {
        int s[5001];

		for (int i = 1; i <= n; ++i) {
			int a; scanf("%d", &a);
			s[i] = a + s[i - 1];
		}

        int ma = -100000;

		for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
			ma = max(ma, s[i] - s[j - 1]);
		}

		printf("%d\n", ma);
	}
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    int a[5000];
    while (cin >> n && n)
    {
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        int max = a[0];
        int S[5000];
        S[0] = a[0];
        for (int i = 1; i < n; i++)
        {
            S[i] = S[i - 1] + a[i];
        }
        for (int l = 0; l < n; l++)
        {
            for (int r = l; r < n; r++)
            {
                int sum = 0;
                if (l != 0)
                {
                    sum = S[r] - S[l - 1];
                }
                else
                {
                    sum = S[r];
                }

                if (sum > max)
                {
                    max = sum;
                }
            }
        }
        cout << max << endl;
    }
}

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

int main(){
	int n,a[5000],s,ans;
	
	while(1){
		cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i] ;
	}
		if(n==0){
			break;
		}
	ans=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			s=0;
			for(int k=j;k<j+i;k++){
				s+=a[k];
			}
			if(ans<s){
				ans=s;
			}
		}
	}
	cout << ans << "\n" ;
	}
return 0;
}

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

int main(){
  int n;
  int a[5000];
  while(cin >> n && n>0){
    for(int i=0;i<n;i++)
      cin >> a[i];
    long long sum=0,tmp=0,ma=-100000;
    int m=-100000;
    bool flg=true;
    for(int i=0;i<n;i++){
      if(flg) m=max(m,a[i]);
      if(a[i]>0){
	flg=false;
	sum+=a[i];
	continue;
      }
      ma=max(ma,sum);
      for(tmp=sum;i<n && a[i]<=0;i++){
	tmp+=a[i];
      }i--;
      if(tmp>0)
	sum=tmp;
      else
	sum=0;
    }

    cout << (flg?m:ma) << endl;
  }
}

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 <vector>
#include <numeric>
#include <iterator>
using namespace std;

int main(void){
	int N;
	while (cin >> N, N) {
		vector<int> a(N);
		for (int i = 0; i < N; i++)
			cin >> a[i];
		vector<int> sums;
		sums.push_back(0);
		partial_sum(a.begin(), a.end(), back_inserter(sums));

		int m = INT_MIN;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				m = max(m, sums[j + 1] - sums[i]);
			}
		}

		cout << m << endl;
	}
}

C++: //Maximum Sum Sequence
#include<bits/stdc++.h>
using namespace std;

int main(){
  while(true){
    int n, max=0, tmp=0;
    cin>>n;
    if(n==0)break;
    for(int i=0; i<n; i++){
      int d;
      cin>>d;
      tmp=(tmp>0 ? tmp+d : d);
      if(max<tmp)max=tmp;
    }
    cout<<max<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int a[5000];
int main(){
int n;
while(true){
cin>>n;
if(n==0)
break;
long long best=-1000000000;
for(int i=0;i<n;i++)
 cin>>a[i];
 
for(int start=0;start<n;start++){
 long long count=0;
 for(int len=start;len<n;len++){
  count+=a[len];
  best=max(best,count);
 }
}

cout<<best<<endl;
}
return 0;   
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
long long dp[6000],n,a,i,maxm;
int main(){
  while(1){
    cin>>n;
    maxm=-999999999;
    if(n==0)break;
    cin>>a;
    dp[1]=maxm=a;
    for(int i=2;i<=n;i++){
      cin>>a;
      dp[i]=dp[i-1]+a;
      if(dp[i]<0)dp[i]=0;
      maxm=max(dp[i],maxm);
    }
    cout<<maxm<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int n, i, k;
    int data[5000];
    while (cin >> n) {
        if (n == 0) {
            break;
        }
        int pdata [5001] = {0};
        int result = 0;
        for (i = 0; i < n; i++) {
            cin >> data[i];
        }
        for (i = 0; i < n; i++) {
            pdata[i + 1] = pdata[i] + data[i];
        }
        for (i = 0; i < n + 1; i++) {
            for (k = 0;  k < n + 1; k++) {
                if (result < pdata[i + k] - pdata[i]) {
                    result = pdata[i + k] - pdata[i];
                }
            }
        }
        cout << result << endl;
    }
    return 0;
}