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++: //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;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
using namespace std;
typedef long long llong;
typedef vector <llong> vll;

int maxv(vll &x){
	int tmp=x[0];
	for (int i=1; i<x.size(); i++)
		if (x[i]>tmp) tmp=x[i];
	return tmp;
}

int main(void){
	int n;
	vll x;
	while (cin>>n, n!=0){
		int s=LLONG_MIN;
		for (int i=0; i<n; i++){
			int n2;
			cin>>n2;

			for (int j=0; j<x.size(); j++){
				x[j] += n2;
			}
			x.push_back(n2);
			if (i==0 || n2>0) s=max(s, maxv(x));
		}
		cout<<s<<endl;
		x.clear();
	}

	return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int data[1000];
        
        rep(i,n) cin>>data[i];
        
        int dp[1000][1000]={};
        
        int maxi=-999999999;
        
        for(int i=0;i<n;i++){
            dp[i][i]=data[i];
            maxi=max( maxi , dp[i][i] );
            
            for(int j=i+1;j<n;j++){
                dp[i][j]=dp[i][j-1]+data[j];
                maxi=max( maxi , dp[i][j] );
            }
        }
        
        cout<<maxi<<endl;
    }
}

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

int main(){
	int n, max, sum, a[5001];

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

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

int maxsum(const vector<int>& data){
  int maxsumval=0,n=data.size();
  for(int i=0;i<n-1;i++){
    int sum=0;
    for(int j=0;j<n-i;j++){
      sum+=data[i+j];
      if(sum>maxsumval)maxsumval=sum;
    }
  }
  return maxsumval;

}
int main(){
  int n;
  while(cin>>n&&n){
    vector<int> data(n);
    for(int i=0;i<n;i++){
      cin>>data[i];
    }
    int maxsumval=maxsum(data);
    cout<<maxsumval<<endl;
  }

}

C++: #include<stdio.h>

int main(void)
{
	int n,x,t,max,r=1;
	for(;r=1;)
	{
		scanf("%d",&n);
		t=0;
		max=0;
		int a[5000]={0},sum[5000]={0};

		for(x=1;x<=n;x++)
		{
			scanf("%d",&a[x]);
			if(a[x]==0)
			{
				r=0;
				break;
			}
			else if(a[x]>0&&a[x-1]>=0)
			{
				sum[t]+=a[x];
			}
			else if(a[x]<0&&a[x-1]<=0)
			{
				sum[t]+=a[x];
			}
			else if(a[x]>0&&a[x-1]<0)
			{
				t++;
				sum[t]+=a[x];
			}
			else if(a[x]<0&&a[x-1]>0)
			{
				t++;
				sum[t]+=a[x];
			}
		}
		if(r==0)
		{
		}
		else if(sum[0]<0)
		{
			x=1;
		}
		else
		{
			x=0;
		}
		if(r==0)
		{
		}
		else if(sum[t]<0)
		{
			t--;
		}

		int y;
		y=x;
		int b[5000][5000]={0};
		
		if(r==0)
		{
		}
		else if(x==t)
		{
			max=sum[x];
			printf("%d\n",max);
		}
		else
		{
			for(x;x<=t;x++)
			{
				for(y;y<=t;y++)
				{
					if(y==0)
					{
						b[x][y]=sum[y];
					}
					else
					{
						b[x][y]=b[x][y-1]+sum[y];
					}

					if(b[x][y]>max)
					{
						max=b[x][y];
					}
				}
			}
			printf("%d\n",max);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	int a[10000],n,s,m;
	while(cin>>n,n){
		m=INT_MIN;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=1;i<=n;i++){
			for(int j=0;j<n-i+1;j++){
				s=0;
				for(int k=0;k<i;k++){
					s+=a[j+k];
				}
				m=max(m,s);
			}
		}
		cout<<m<<endl;
	}
}

C++: #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

char s[10000];

int main()
{
	while(1)
	{
		int n;
		scanf("%d",&n);
		if(n == 0)
		{
			break;
		}
		long long int maxw = -10000000000000;
		long long int ms = 0;
		long long int now = 0;
		for(int i = 0; i < n; i++)
		{
			long long int w;
			scanf("%lld",&w);
			now += w;
			maxw = max(maxw,now - ms);
			ms = min(ms,now);
		}
		printf("%lld\n",maxw);
	}
	return 0;
}

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


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

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

int main(){
    int n;
    while(cin >> n && n){
        vector<int> a(n,0);
        for(int i=0; i<n; ++i){
            cin >> a[i];
        }
        // ????????£?¶??????????????????§??£?¶???????dp??¨?????????
        vector<int> dp(n,0);
        dp[0] = a[0];
        int max = 0;
        for(int i=1; i<n; ++i){
            if(dp[i-1]>0){
                dp[i] = dp[i-1] + a[i];
            } else {
                dp[i] = a[i];
            }
            if(max<dp[i]){
                max = dp[i];
            }
        }
        cout << max << endl;
    }
}

C++: #include <iostream>

using namespace std;

template <typename Type>
long long Maximum_Sum_Sequence(Type N[], int size)
{
	long long max = LLONG_MIN;

	for (int i = 0; i < size; i++)
	{
		long long sum = 0;

		for (int j = i; j < size; j++)
		{
			sum += N[j];

			if (sum > max) { max = sum; }
		}
	}

	return max;
}

int main()
{
	const int DATASETS = 10;

	int n[DATASETS], a[DATASETS][5000], c = 0;

	while (true)
	{
		cin >> n[c];

		if (n[c] == 0) { break; }

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

		c++;
	}

	for (int i = 0; i < c; i++)
	{
		cout << Maximum_Sum_Sequence(a[i], n[i]) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <climits>
int main()
{
  while (1) {
    int n;
    std::cin >> n;
    if (n == 0) break;
    int max = -INT_MAX;
    int a[n];
    for (int i = 0;i < n; i++) {
      std::cin >> a[i];
    }
    for (int i  = 0; i < n; i++) {
      if (a[i] < 0) continue;
      int temp = a[i];
      for (int j = i + 1; j < n; j++) {
        temp += a[j];
        if (temp > max) max = temp;
      }
    }
    std::cout << max << std::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;
  vector<int>in(n);
  while(cin>>n,n){
    rep(i,n)cin>>in[i];
    int max=0;
    rep(i,n){
      int sum=0;
      loop(j,i,n){
	sum+=in[j];
	if(max<sum)max=sum;
      }

    }
    cout<<max<<endl;
  }


}