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

int main(){
	long long int n;
	long long int i;
	long long int max;
	long long int sum[1000000];
	long long int t;
	while(cin>>n,n){
		max=0;
		for(i=0;i<n;i++)cin>>sum[i];
		for(i=t=0;i<n;i++){
			if(t<0)t=sum[i];else t+=sum[i];
			if(max<t)max=t;
		}
		cout<<max<<endl;
	}
}

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

int main()
{
    int n;
    while(1){
        vector<int>vec;
        int ans=-100000;
        cin>>n;
        vector<int>dp(n);
        if(n==0)break;
        for(int i=0;i<n;i++){
            int a;cin>>a;
            vec.push_back(a);
        }
        dp[0]=vec[0];
        for(int i=1;i<n;i++){
            dp[i]=max(dp[i-1]+vec[i],vec[i]);
        }
        for(int i=0;i<n;i++){
            ans=max(ans,dp[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <climits>
#include <numeric>
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++) {
      for (int j = i + 1; j <= n; j++) {
        int temp = std::accumulate(a + i, a + j, 0);
        if (temp > max) max = temp;
      }
    }
    std::cout << max << std::endl;
  }
}

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

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

using namespace std;

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

const int INF = 1000000000;
const int MOD = 1000000007;
const double EPS = 1e-8;

int main() {
	int n;
	while (cin >> n, n) {
		int a[n], ans = -10000000;
		rep (i, n) cin >> a[i];
		int dp[n];
		dp[0] = a[0];
		REP (i, 1, n) {
			dp[i] = max(dp[i - 1] + a[i], a[i]);
		}
		rep(i, n) {
			cout << dp[i] << " ";
			ans = max(ans, dp[i]);
		}
		cout << endl;
		cout << ans << endl;
	}
}

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

int main() {
	int n;
	while (true) {
		cin >> n;
		if (n == 0)break;
		int* nums = new int[n];
		for (int i = 0; i < n; i++) {
			cin >> nums[i];
		}
		long int max = -100001; 
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n - i; j++) {
				long int tmp = 0;
				for (int k = i; k <= j; k++) {
					tmp += nums[k];
				}
				if (max < tmp)max = tmp;
			}
		}
		cout << max << endl;
	}
}

C++: #include <algorithm>
#include <iostream>
using namespace std;
int a[5010];
int main(){
	int i,n,max_so_far,max_ending_here;//maximum subarray problem
	cin>>n;
	while(n!=0){

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

		max_ending_here=-100000;
		max_so_far=-100000;

		for(i=0;i<n;i++){
			max_ending_here = max(0,max_ending_here + a[i]);
			max_so_far = max(max_so_far,max_ending_here);
		}
	cout << max_so_far << endl;
	cin>>n;//kousinn
	}
}

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

int main(){
	const int MAX_n = 5000;
	int n, a[MAX_n + 1], z, beg, res;
	
	while(true){
		scanf("%d", &n);
		
		if(n == 0) return 0;
		
		a[0] = 0;
		for(int i = 1; i <= n; i++){
			scanf("%d", &z);
			a[i] = z + a[i - 1];
		}
		
		beg = 0;
		res = -100000;
		for(int i = 1; i <= n; i++){
			beg = min(beg, a[i - 1]);
			res = max(res, a[i] - beg);
		}
		
		printf("%d\n", res);
	}
}

C++: #include <stdio.h>

int main()
{
	int n, x, p, i, j, k;
	
	while(scanf("%d", &n) != 0){
		if (n == 0) break;

		int a[n];

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

		x = a[0];

		for(i = 1; i <= n; i++){
			for(j = 0; j < n-i+1; j++){
				if(j == 0 || a[j+i-1] > a[j-1]){
					p = 0;

					for(k = 0; k < i; k++){
						p += a[j+k];
					}

					if(x < p) x = p;
				}
			}
		}

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

	return 0;
}

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

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

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

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		int sum=0,a[5001];
		vector<int>anss(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];
				anss.push_back(sum);
			}
		}
		sort(anss.begin(),anss.end(),greater<int>());
		cout<<anss[0]<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
  int n,i,j,k,max,sum;
  while(1){
    int max=-100000;
    cin>>n;
    int a[n];
    if (n==0) break;
    for (i=0;i<n;i++){
      cin>>a[i];
    }
    for (i=0;i<n;i++){
      sum=0;
      for (j=0;j<n-i;j++){
        sum=sum+a[i+j];
        if (max<sum) max=sum;
      }
    }
    cout<<max<<endl;
  }
}

C++: #include<iostream>
#include<cstring>
using namespace std;
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
    long int s[N];
    int n;
    while(cin >> n &&n)
    {
        memset(s,0,sizeof(int)*N);
        int t;
        long int max = 0;
        long int min = 0;
        for(int i=0;i<n;i++){
            cin >>t;
            s[i+1] = s[i]+t;
            if(max<s[i+1])max = s[i+1];
            if(min>s[i+1])min = s[i+1];
        }
        cout << max -min << endl;

    }

    return 0;
}