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>
using namespace std;

int main(){
        int n,a[5010];
        while(cin >> n && n){
                int buf,j=0;
                for(int i=0; i<n; i++){
                        cin >> buf;
                        if(i>0 && a[j]*buf>=0) a[j] += buf;
                        else a[++j] = buf;
                }
                long max = 0;
                for(int i=0; i<=j; i++){
                        for(int k=i; k<=j; k++){
                                long sum = 0;
                                for(int l=i; l<=k; l++){
                                        sum += a[l];
                                }
                                max = (max > sum)? max:sum;
                        }
                }
                cout << max << endl;
        }
}

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

int main(){
  int n,m,s,a;
  // while(cin>>n,n)
  // int i,j;
  // i=1;
  // j=++i;
  // cout << i<<j;
  // i=1;
  // j=i++;
  // cout << i<<j;
  // while(++i,i<=10)
  //   cout<<i<<endl;
  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;
  }
  return 0;
}

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

using namespace std;
static const int MAXV = 5000;

int main() {
  while(1) {
    int n, data[MAXV], max=0, sum=0;
    scanf("%d", &n);
    if (n==0) break;
    for(int i=0; i<n; i++) scanf("%d", &data[i]);
    //cout << data[0] <<" " << data[1] <<endl;
    for (int i=0; i<n; i++) {
      for (int j=i; j<n; j++) {
	sum+=data[j];
	if(max<sum) max=sum;
      }
      sum=0;
    }
    printf("%d", max);
  }
}

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

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

int n;
vector<int> v;

long long s[5000][5000];

int main(){
    while(cin>>n,n){
        v=vector<int>(n);
        REP(i,n)cin>>v[i];
        long long ans=-(1<<30);
        REP(i,n){
            s[i][i]=v[i];
            ans=max(s[i][i],ans);
            for(int j=i+1; j<n; j++){
                s[i][j]=s[i][j-1]+v[j];
                ans=max(s[i][j],ans);
            }
        }
        cout<<ans<<endl;
    }
}

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

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

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

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

using namespace std;

int main() {

    int n;

    while(cin >> n, n) {

        int num[n];
        int dp[n + 1][n + 1];

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

        memset(dp, 0, sizeof(dp));

        for(int i = 1; i <= n; ++i) {
            for(int j = i; j <= n; ++j) {
                dp[i][j] = dp[i][j - 1] + num[j - 1];
                if(dp[i][0] < dp[i][j]) {
                    dp[i][0] = dp[i][j];
                }
            }
            if(dp[i][0] < dp[i - 1][0]) {
                dp[i][0] = dp[i - 1][0];
            }
        }

        cout << dp[n][0] << endl;

    }

}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[3000];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-2]);
			}
		}
		cout<< ans <<endl;
	}
}

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];
        
        ll maxi=-999999999999;
        
        for(int i=0;i<n;i++){
            ll sum[1000]={};
            sum[i]=data[i];
            maxi=max(maxi,sum[i]);
            
            for(int j=i+1;j<n;j++){
                sum[j]=sum[j-1]+data[j];
                maxi=max(maxi,sum[j]);
            }

        }
        
        
        cout<<maxi<<endl;
    }
}

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

int main(){
	int n;
	int a;
	int sum;
	int sum2;
	int sum3;
	long int max;
	cin >> n;
	while(n){
		cin >> sum;
		cin >> sum2;
		sum += sum2;
		max = sum;
		for(int i=0;i<n-2;i++){
			cin >> sum3;
			sum += sum3;
			sum2 += sum3;
			if(sum < sum2){
				sum = sum2;
			}
			if(sum > max){
				max = sum;
			}
			sum2 = sum3;
		}
		cout << max << endl;
		cin >> n;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
using namespace std;
int maxsum(int x,vector<int> a){
	
	vector<int> s(x+1,0);
	int max;
	for(int i=1;i<=x;i++){
		if(s[i-1]<0)
			s[i]=a[i];
		else
			s[i]=s[i-1]+a[i];
	}
	for(int i=0;i<=x;i++)
		cout<<s[i]<<" ";
	cout<<endl;
	max = *max_element(s.begin(),s.end());
	return max;
	
}

int main(){
	
	int n;
	while(cin>>n,n!=0){
		
		vector<int> a(n+1,0);
		
		for(int i=1;i<=n;i++)
			cin>>a[i];
		
		cout<<maxsum(n,a)<<endl;
	}
	
 	
}

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

int main()
{

	int n, num;
	vector< int > a;

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

		int Max = -100001;

		a.push_back( 0 );

		for( int i = 0; i < n; i++ ) {

			cin >> num;
			a.push_back( num );

		}

		for( int i = 1; i <= n; i++ ) {

			a[i] = max( a[i], a[i] + a[i - 1] );
			Max  = max( Max, a[i] );
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

C++: #include<iostream>

using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		long long int a[n];
		long long int max=-100000;
		int input;
		for(int i=0;i<n;i++){
			a[i]=0;
			cin>>input;
			for(int j=0;j<=i;j++){
				a[j]+=input;
				if(max<a[j])max=a[j];
			}
		}
		cout<<max<<endl;
	}
	return 0;
}