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>
#include <limits.h>
using namespace std;

int main(){
	int a[10000],b[10000],n,s,m,p,M;
	while(cin>>n,n){
		m=INT_MIN;p=0;M=INT_MIN;
		for(int i=0;i<n;i++){
			cin>>a[i];
			M=max(M,a[i]);
			if(a[i]>=0)p=1;
		}
		if(p==0)m=M; else
		for(int i=1;i<=n;i++){
			for(int j=0;j<n-i+1;j++){
				if(a[j]<0||a[j+i-1]<0)continue;
				s=0;
				for(int k=0;k<i;k++){
					s+=a[j+k];
				}
				m=max(m,s);
			}
		}
		cout<<m<<endl;
	}
}

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

int n,s[5000+10];

int bigger(int n){
    int M=-100000;
    for(int p=1;p<n;p++){
        if(s[p]>M) M=s[p];
        for(int q=0;q<p-1;q++){
            if(s[p]-s[q]>M) M=s[p]-s[q];
        }
    }
    return M;
}

int main(){
    int n;
    while(cin){
        cin >> n;
        if(n==0) break;
        int a[5000+10];
        for(int i=0;i<n;i++){
            cin >> a[i];
            if(i==0) s[i]=a[i];
            else s[i]=s[i-1]+a[i];
        }
        cout << bigger(n) << endl;
    }
}

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

using namespace std;

int main()
{
	while(true)
	{
		int length;
		cin >> length;
		if(length == 0)
			break;

		auto numbers = vector<int>(length);
		for(auto& i : numbers)
			cin >> i;

		int max = -2000001;
		for(int i = 0; i < length; i++)
		{
			int current = 0;
			for(int j = i; j < length; j++)
			{
				current += numbers[j];
				if(max < current)
					max = current;
			}
		}

		cout << max << endl;
	}

	return 0;
}

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

int main()
{
  long n, a, res, t;
  
  while (cin >> n, n){
    res = -100000000;
    t = 0;
    for(int i = 0; i < n; i++){
      cin >> a;
      t = max(t + a, a);
      res = max(res, t);
    }
    cout << res << endl;
  }
}

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

int main(){
	bool flag[5000] = {false};
	int n, in[5000];
	long long ans, tmp = 0ll;
	
	while(true){
		cin >> n;
		if(n == 0)
			break;

		for(int i = 0; i < n; ++i){
			cin >> in[i];
			if(in[i] > 0)
				flag[i] = true;
		}//input

		for(int i = 0; i < n; ++i){
			for(int j = i + 1; j < n; ++j){
				if(flag[i] && flag[j]){
					for(int k = i; k <= j; ++k)
						tmp += in[k];
					if(tmp > ans){
						ans = tmp; 
						tmp = 0ll;
					}	
					else
						tmp = 0ll;
				}
			}
		}
		
		cout << ans << endl;//output
		
		ans = 0ll;
		for(int i = 0; i < n; ++i)
			flag[i] = false;//intialize
	
	}
	return 0;
}

C++: #include <stdio.h>

int main(){
	int n;
	int buf[5000];
	long goukei;
	long max;
	
	int i,j;
	
	while(1){
		goukei = 0;
		max = -20000;
		scanf("%d",&n);
		if(n == 0)break;
		for(i = 0;i < n;i++){
			scanf("%d",&buf[i]);
		}
		
		for(i = 0;i < n;i++){
			goukei = 0;
			for(j = i;j < n;j++){
				goukei += buf[j];
				if(goukei > max){
					max = goukei;
				}
			}
		}
		
		printf("%d\n",max);
	}
	
	return 0;
}

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;
        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;
}

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=dset[0];
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(){
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>
#include <numeric>
#include <iterator>
#include <climits>
using namespace std;

int main(void){
	int N;
	while (cin >> N, N) {
		vector<int> a(N);
		for (int i = 0; i < N; i++)
			cin >> a[i];
		vector<int> sums;
		sums.push_back(0);
		partial_sum(a.begin(), a.end(), back_inserter(sums));

		int m = INT_MIN;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				m = max(m, sums[j + 1] - sums[i]);
			}
		}

		cout << m << endl;
	}
}

C++: #include <iostream>
using namespace std;
int main(){
  int a,n;
  long max,sam;
  while(cin>>a,0!=a){
    cin>>n;
    max=sam=n;
    for(int i=0;i<a-1;i++){
      cin>>n;
      if(sam<0)sam=n;
      else{
        sam+=n;
      }
      if(sam>max)max=sam;
    }
    cout<<max<<endl;
  }
}

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

const int INF = 1e+9 * 2;

int main() {
	int n;
	while(cin >> n && n){
		int a[5010] = {0};
		for(int i = 0; i < n; ++i)
			scanf("%d", &a[i]);
		int ans = -INF;
		for(int i = 0; i < n; ++i){
			int sum = 0;
			for(int j = i; j < n; ++j){
				sum += a[j];
				if(ans < sum)
					ans = sum;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
int main(){
	int n;
	while(std::cin >> n, n){
		std::vector<int> v;
		for(int i=0;i<n;i++){
			int a;
			std::cin >> a;
			v.push_back(a);
		}

		int max = v[0];
		for(int i=0;i<n;i++){
			int k = 0;
			for(int j=i;j<n;j++){
				k += v[j];
				if(k > max)max = k;
			}
		}

		std::cout << max << std::endl;
	}	
}

C++: #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

int main(){
  int n;
  while(cin>>n && n!=0){
    vector<int> vec(n),sum(n);
    rep(i,n) cin>>vec[i];
    sum[0]=vec[0];
    
    for(int i=1;i<n;i++) sum[i]=vec[i]+sum[i-1];
    int ma=-1e9;
    
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        chmax(ma,sum[j]-sum[i]);
      }
    }
    
    rep(i,n) chmax(ma,sum[i]);
 
    cout<<ma<<endl;
  }
  
  return 0;
}