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(){
	int n;
	cin >> n;
	while(n != 0){
		int a[n];
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}

		sort(a, a + n);
		int sum = 0;
		for(int i = 0; i < n; i++){
			if(a[n-1-i] > 0){
				sum += a[n-1-i];
			}else{
				cout << sum << endl;
				break;
			}
		}
		cin >> n;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
#define NMAX 5100

//int dp[NMAX][NMAX];
int a[NMAX];

int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0)break;
        memset(dp,0,sizeof(int)*NMAX);
        memset(a,0,sizeof(int)*NMAX);

        for(int i =1;i<=n;++i)
        {
            cin >> a[i];
        }
        int sum = 0,ans = 0;
        for(int first = 1;first<=n; ++first)
        {
            for(int last = first;last<=n;++last)
            {
                sum += a[last];
                if(ans<sum) ans = sum;
            }
            sum = 0;
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000001

using namespace std;
#define ll long long
#define dbg if(0)



int main(){
    while(true){
        int n;
        ll ans= LLONG_MIN;
        cin>>n;
        if (n==0)break;

        ll rui[n+1];
        rui[0]=0;
        ll lowmax=LLONG_MIN;
        for(int i=1;i<=n;i++){
            cin >>rui[i];
            if(rui[i]<=0)lowmax=max(lowmax,rui[i]);
            rui[i]+=rui[i-1];
            dbg cout <<rui[i]<<" ";
        }
        dbg cout <<endl;
        //次を見る
        //今までの最小値を更新したか？
        //したなら暫定解を確定しansと比較。最大値=最小値=発見した最小値にする
        //してなければ最大値の更新をする
        //見る場所が一番後ろまで行ったら終了。
        rui[0]=min(rui[0],rui[1]);
        ll nmin=rui[0],nmax=rui[0];
        bool nmflag=false;
/*        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                ans=max(rui[j]-rui[i-1],ans);
            }
        }*/
        for(int i=0;i<=n;i++){
            if (rui[i]<nmin){
                ans=max(nmax-nmin,ans);
                nmax=rui[i];
                nmin=rui[i];
            }else{
                if(rui[i]>nmax){
                    nmax=rui[i];
                    nmflag=true;
                }
            }
            dbg cout <<nmax<<" "<<nmin<<" "<<endl;
        }
        ans=max(nmax-nmin,ans);
        dbg cout << endl;
        if(nmflag)cout<<ans<<endl;
        else cout<<lowmax<<endl;
        //cout <<ans<<endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
int main() {
  int n, input;
  vector<int> input_v;
  vector<int> part_v;
  int max_num = 0;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    input_v.clear();
    while(n--) {
      cin >> input;
      input_v.push_back(input);
    }
    max_num = 0;
    for (int i = 0; i < input_v.size(); ++i) {
      for (int len = 2; len <= input_v.size() - i; ++len) {
        part_v.clear();
        for (int m = 0; m < len && i + m < input_v.size(); ++m) {
          part_v.push_back(input_v[i + m]);
        }
        max_num = max(accumulate(part_v.begin(), part_v.end(), 0), max_num);
      }
    }
    cout << max_num << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,s,a;
	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;
	}
}

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

int main() {
 int n;
 int a[5000];
 int S[5000];
 while ((cin >> n) && n != 0) {
  for (int i=0; i<n; ++i) {
   cin >> a[i];
  }
  S[0] = 0;
  for (int i=0; i<n; ++i) {
   S[i+1] = S[i] + a[i];
  }
  int max = -100001;
  for (int i=0; i<n; ++i) {
   for (int j=i+1; j<=n; ++j) {
    max = (S[j]-S[i] > max) ? S[j]-S[i] : max;
   }
  }
  cout << max << endl;
 }
}

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

int main(){
  int n,a[5000];

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

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  while( cin >> n ,n)
    {
      int a[5101] = {0};
      for(int i = 0 ; i < n ; i++ )
	{
	  cin >> a[i];
	}

      int dp[5101] = {0},mx = 0;

      dp[0] = a[0];
      for(int i = 1 ; i <= n ; i++ ){
	dp[i] = max(dp[i-1] + a[i],a[i]); 
	mx = max(dp[i],mx);
      }
      cout << mx << endl;
    }
  return 0;
}

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


int main()
{
    for (int n; cin >> n && n;) {
        vector<int> sequence(n);
        int sum = 0;
        int min = 0;
        int max = numeric_limits<int>::min();
        for (int x, i = 0; i < n && cin >> x; i++) {
            sum += x;
            if (sum > max)
                max = sum;
            if (sum < min)
                min = sum;
        }
        cout << max - min << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int a[5000],n;
signed main(){
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>a[i];
        int ma=0;
        for(int i=0;i<n;i++){
            int cur=0;
            for(int j=i;j<n;j++){
                cur+=a[j];
                ma=max(ma,cur);
            }
        }
        cout<<ma<<endl;
    }

    return 0;
}

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

int main() {
	while (1) {
		int n;
		cin >> n;
		if ( n == 0 ) break;
		int a[5000];
		for ( int i = 0; i < n; i++ ) {
			cin >> a[i];
		}
		int ans = a[0];
		int pn;
		for ( int i = 0; i < n; i++ ) {
			pn = 0;
			for ( int j = 0; i + j < n; j++ ) {
				pn += a[i + j];
				if ( pn > ans ) ans = pn;
			}
		}
		cout << ans << endl;
	}
}

C++: #include <stdio.h>

#define SGN(X) ((X)>0?1:(X)<0?-1:0)
int compressRead(int a[], int n);

int main(void){
	int n;
	int a[5000];
	int max, cur;
	
	while (scanf("%d", &n), n){
		n = compressRead(a, n);
/*		printf("a[%d]:", n);
		for (int i=0; i<n; i++){
			printf("%d ", a[i]);
		}
		puts(""); */
		max = a[0];
		for (int i=0; i<n; i++){
			cur = 0;
			for (int j=i; j<n; j++){
				cur += a[j];
				if (cur > max) max = cur;
			}
		}
		printf("%d\n", max);
		for (int i=0; i<n; i++) a[i]=0;
	}
	
	return 0;
}

int compressRead(int a[], int n){
	int idx=0;
	int x,last;
	
	scanf("%d", &x);
	last=a[idx]=x;
	for (int i=1; i<n; i++){
		scanf("%d", &x);
		if (x==0) continue;
		if (x<0){
			a[++idx] = x;
//			printf("a[%d] = \%d\n",idx,x);
		}else{
			if (last<0) a[++idx]=0;
			a[idx]+=x;
//			printf("a[%d] += %d (=%d)\n", idx, x, a[idx]);
		}
		last = x;
	}
	
	return idx+1;
}