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 a[5000];
	int left[5000], right[5000];
	int n;
	
	while (true) {
		cin >> n;
		if (n==0) break;
		
		bool existsPos = false;
		for (int i=0; i<n; i++) {
			cin >> a[i];
			if (a[i] > 0) existsPos = true;
		}
		
		int maximum;
		
		if (existsPos) {
			int left_max = a[0];
			int left_max_pos = 0;
			left[0] = a[0];
			for (int i=1; i<n; i++) {
				left[i] = left[i-1] + a[i];
				if (left[i] > left_max) {
					left_max = left[i]; left_max_pos = i;
				}
			}
			int right_max = a[n-1];
			int right_max_pos = n-1;
			right[n-1] = a[n-1];
			for (int i=n-2; i>=0; i--) {
				right[i] = right[i+1] + a[i];
				if (right[i] > right_max) {
					right_max = right[i]; right_max_pos = i;
				}
			}
			
			maximum = 0;
			for (int i = right_max_pos; i <= left_max_pos; i++) maximum += a[i];
		}
		else {
			maximum = -100000;
			for (int i=0; i<n; i++) {
				if (a[i] > maximum) maximum = a[i];
			}
		}
		
		cout << maximum << endl;
	}
		
	return 0;
}

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=S[0];
		for(int i=0;i<n;++i){
			if(S[i]>max) max=S[i];
			for(int j=0;j<i+1;++j){
				if(S[i]-S[j]>max) max=S[i]-S[j];
			}
		}

		cout<<max<<endl;
	}

	return 0;

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

vector<long long> num;
long long dp[5000];

void init(){
  for(int i = 0; i < 5000; i++){
    dp[i] = 0;
  }
  num.clear();
}

int main(void){
  while(true){
    long long maximum = 0, n;
    cin >> n;
    if(!n)  break;
    init();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < n; i++){
      dp[i] = max(dp[i-1] + num[i], num[i]);
    }
    
    for(int i = 0; i < n; i++){
      if(dp[i] > maximum) maximum = dp[i];
    }

    cout << maximum << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int stage[100000] = {0};
        for(int i = 1;i <= n; i++){
            scanf("%d",&stage[i]);
        }
        int x = 0;
        int ans = -1000000;
        for(int i = 1;i <= n; i++){
            for(int j = i;j <= n; j++){
                x += stage[j];
                ans = max(ans,x);
            }
            x = 0;
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

template<typename T>
T m(T a, T b) { return a > b ? a : b; }

int main(void) {
    freopen("i.in", "r", stdin);
    int N;
    while(true) {
        cin >> N;
        if(N == 0) break;
        vector<int> v(N);

        for(int i = 0; i < N; i++) cin >> v[i];

        long long mx = -100000L;

        for(int i = 0; i < N; i++) {
            long long tmp = 0L;
            for(int j = i; j < N; j++) {
                tmp += v[j];
                mx = m(mx, tmp);
            }
        }
        cout << mx << 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;
			}
		}
		cin >> n;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int i;
	long max;
	long total;
	int a[5010];
	int n;
	
	while (scanf("%d", &n), n != 0){
		max = 0;
		total = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
			total += a[i];
			if (total < 0){
				total = 0;
			}
			if (max < total){
				max = total;
			}
		}
		printf("%d\n", max);
	}
	return (0);
}

C++: #include <iostream>

using namespace std;

int main(void){
	int n;
	long long int a[5000]={0};
	while(cin >> n){
		long long int max = 0;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			cin >> a[i];
		}
		for(int i=0;i<n;i++){
			long long int sum = 0;
			for(int j=0;i+j<n;j++){
				sum += a[i+j];
				if(j!=0&&max < sum) max = sum;
			}
		}
		cout << max << "\n";
	}
	return 0;
}

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[2500];
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-1]);
			}
		}
		cout<< ans <<endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int l = 0;
    while(cin >> number)
    {
        int a[5010] = {0};
        vector<int>tempmax2(5010,0);
        int temp = 0;
        REP(i,number)
        cin >> a[i];
        for(int j = 0; j<number;j++)
            for(int k = j;k<number;k++)
            {
                for(int l = k;l<number;l++)
                {
                    if(k == l)
                        tempmax2[k] = a[k];
                    else{
                        
                        tempmax2[k] += a[l];
                    }
                    if(temp <= tempmax2[k])
                        temp = tempmax2[k];
                }
            
            }
        //sort(tempmax.begin(),tempmax.end(),greater<int>());
        //sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        //if(tempmax[0]>temp)
            //answer[l] = tempmax[0];
        //else
        // answer[l] = temp;
        printf("%d\n",temp);
        temp = 0;
    }
    return 0;
}