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 <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;


int main()
{
	int n;
	cin >> n;
	while(n!=0){
		vector<int>dp;
		dp.pb(0);
		rep(i,n){
			int t;
			cin >> t;
			dp.pb(dp[i]+t);
		}
		int mx=0;
		rp(i,dp){
			REP(j,i+1,dp.size()){
				mx=max(mx,dp[j]-dp[i]);
			}
		}
		cout << mx << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int s[5000];

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    cin >> s[0];
    int r = s[0], m = 0;
    for (int i = 1; i < n; i++) {
      cin >> s[i];
      r = max(r, s[i]);
      s[i] += s[i-1];
    }
    for (int i = 0; i < n; i++)
      if (s[i] < m)
        m = s[i];
      else
        r = max(r, s[i]-m);
    cout << r << endl;
  }
}

C++: #include <stdio.h>
#include <limits.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#define swap(type, x, y) do{type temp = x; x = y; y = temp;}while(0);
using namespace std;
void quick_sort(long long int x[], int left, int right);
int main(void) {
    int num;
    
    while(1) {
        scanf("%d", &num);
        if(num == 0) break;
        
        long long int sum[num + 1];
        int i, value;
        
        for(i = 0; i < num + 1; i++) {
            sum[i] = 0;
        }
        
        for(i = 0; i < num; i++) {
            scanf("%d", &value);
            sum[i + 1] += sum[i] + value;
        }
        quick_sort(sum, 1, num);
        
        cout << sum[1] << endl;
    }
    
    return(0);
}

void quick_sort(long long int x[], int left, int right) {
    int i, j;
    long long int pivot;
    
    i = left;
    j = right;
    pivot = x[(left + right) / 2];
    
    while(1) {
        while(x[i] > pivot) i++;
        while(x[j] < pivot) j--;
        
        if(i >= j) break;
        
        swap(long long int, x[i], x[j]);
        i++;
        j--;
    }
    if(i - 1 > left) quick_sort(x, left, i - 1);
    if(j + 1 < right) quick_sort(x, j + 1, right);
}

C++: #include<stdio.h>
int main(){
    int a;
    while(1){
        scanf("%d",&a);
        if(a==0)return 0;
        int n[5000];
        for(int i=0;i<a;i++)scanf("%d",n+i);
        int dp[5000];
        dp[0]=n[0];
        int max=0;
        for(int i=1;i<a;i++){
            if(dp[i-1]>0)dp[i]=dp[i-1]+n[i];
            else dp[i]=n[i];
            if(max<dp[i])max=dp[i];
        }
        printf("%d\n",max);
    }
}

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=ma>sum?ma:sum;
      for(tmp=sum;i<n && a[i]<=0;i++){
	tmp+=a[i];
      }i--;
      if(tmp>0)
	sum=tmp;
      else
	sum=0;
    }
    ma=ma>sum?ma:sum;

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

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


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


int main(){
	for (int n; cin >> n, n != 0; ) {
		vi a(n);
		rep(i, n) cin >> a[i];
		int ans = -1000000;
		rep(i, n) {
			int sum = 0;
			REP(j, i, n - 1) ans = max(ans, sum += a[j]);
		}
		cout << ans <<endl;
	}
	
	return 0;
}

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

int main(){
	int n;
	int a;
	int sum;
	cin >> n;
	while(n){
		cin >> sum;
		for(int i=0;i<n;i++){
			cin >> a;
			if(sum < a){
				sum = a;
			}else{
				sum += a;
			}
		}
		cout << sum << endl;
		cin >> n;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
while(true)
{
int n;
cin >> n;
if(n == 0)return 0;
int* numbers = new int[n];
for(int i = 0;i < n;i++)
cin >> numbers[i];
int max = 0;
for ( int i = 0; i < n; i++){
int sum = 0;
for ( int j = i; j < n; j++){
sum += numbers[j];
if(max < sum)max = sum;
}
}
cout << max << endl;
}
}

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

int main(void)
{
	vector<int> numbers;
	int count, tmp, ans[5000], Max;

	while (cin >> count) {
		if (count == 0) break;
		for (int i = 0; i < 5000; i++) ans[i] = 0;
		Max = 0;
		for (int i = 0; i < count; i++) {
			cin >> tmp;
			for (int j = 0; j <= i; j++) {
				ans[j] += tmp;
				if (Max < ans[j]) Max = ans[j];
			}
		}
		cout << Max << endl;
	}
	
	return 0;
}