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<cstring>
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
    int n;
    while(cin >> n &&n)
    {
        if(n==0)break;
        long int s[N];
        //memset(s,0,sizeof(int)*N);
        int t;
        long int max = 0;
        long int min = 0;
        /*cin >> t;
        s[0]=t;max = t;min=t;*/
        s[0] = 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];
        }
        if(n==1) {cout << max << endl; continue;}
        cout << max - min << endl;

    }

    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

int main() {
  int n;

  while(cin >> n, n) {
    VI a(n);
    REP(i, n) cin >> a[i];

    int ans = 0;
    REP(i, n) {
      int sum = 0;
      FOR(j, i, n) {
	sum += a[j];
	ans = max(sum, ans);
      }
    }

    cout << ans << endl;
  }
}

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

int a[5000] = {0};
int S[5001] = {0};

int main() {
  int n;
  while(cin >> n) {
  if(n == 0) break;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for(int i = 1; i <= n; i++) {
    S[i] = S[i-1] + a[i-1];
  }
  

  int maxsum = 0;
  int sum = 0;
  for(int i = 0; i <= n-1; i++){
    for(int j = i + 1; j <= n;j++) {
      sum = S[j] - S[i];
      if(sum > maxsum)
	maxsum = sum;
      sum = 0;
    }
  }
  cout << maxsum << endl;
  }
}

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

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

int main()
{
	int n;
	while(cin>>n){
		if(n==0) break;
		int a[n], S[n], sum=0;
		for(int i=0;i<n;++i){
			cin>>a[i];
			sum+=a[i];
			S[i]=sum;
		}

		long max=-99999999;
		for(int i=0;i<n;++i){
			if(S[i]>max) max=S[i];
			for(int j=0;j<n-1;++j){
				if(S[i]-S[j]>max) max=S[i]-S[j];
			}
		}

		cout<<max<<endl;
	}

	return 0;
}

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

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

int main(){
  int n;
  long a[5010];
  long s[5010];
  while(cin>>n && n){
    long mx=0;
    for( int i=1;i<=n;i++ ){
      cin >> a[i];
      mx = max(mx, a[i]);
    }
    for( int i=1;i<=n;i++ ){
      s[i] = a[i];
      for( int j=i+1;j<=n;j++ ){
	s[j] = s[j-1] + a[j];
	mx = max(mx, s[j]);
      }
    }

    cout << mx << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;


int main(void){

int nm=9;
int sum, wk;

	while( nm != 0){
		cin >> nm;
		if(nm == 0) break;
		int mx = -999999999; sum=0;
		rep(i,nm){
			cin >> wk;
			sum += wk;
			mx = max(mx,sum);
		}
		cout << mx << endl;
	}
	return 0;
}

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

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

  return 0;
}

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

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

#define MAX_N 5000

int main(){
    int n, ans = 0, in, before;
    while(std::cin >> n, n){
        std::cin >> before;
        ans = before;
        for(int i = 1; i < n; ++i){
            std::cin >> in;
            before = std::max(in, before + in);
            ans = std::max(before, ans);
        }
        std::cout << ans << std::endl;
        ans = 0, before = 0;
    }
    return 0;
}

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

using namespace std;

int debug = 0;

int main(void){
	int n, m, i, j, k;
	int tmp, max;
	vector<int> intv;

	while(cin >> n){
		if(n == 0){
			break;
		}else{
			//ÇÝÝ
			for(i=0;i<n;i++){
				cin >> m;
				intv.push_back(m);
				if(debug) cout << "int[" << i << "] =" << intv[i] << endl; 
			}

			//vfð¸ç·
			for(i=0;i<intv.size()-1;i++){
				if((intv[i] > 0 && intv[i+1] > 0)||
					(intv[i] < 0 && intv[i+1] < 0)){
					intv[i] += intv[i+1];
					intv[i+1] = 0;
					intv.erase( remove(intv.begin(), intv.end(), 0), intv.end());
					i = 0;
				}
			}

			for(i=0;i<intv.size();i++){
				if(debug) cout << intv[i] << endl;
			}

			max = 0;
			int vsize = intv.size();
			for(i=1;i<=vsize;i++){//i:Â
				if(debug) cout << "number =" << i << endl;
				for(j=0;j<=vsize-1-i+1;j++){ //j:JnÊu
					tmp = 0;
					for(k=0;k<i;k++){
						tmp += intv[j+k];
					}
					if(debug) cout << "tmp ==" << tmp << endl;
					if(max <= tmp){
						max = tmp;
					}
				}
			}
			cout << max << endl;
			intv.clear();
		}
	}
	return 0;
}