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<limits>
 using namespace std;

 int main()
 {
     while(1){
         int n;
         cin >> n;
         if( !n ) break;

         int a;
         int max = numeric_limits<int>::min();
         int sum = numeric_limits<int>::min();
         for(int i=0; i<n; i++){
             cin >> a;

             if( max<0 && a<0 && max<a ) { max = a; continue; }
             else if( max<0 && a<0 && max>a){ continue; }

             if( a>0 ){
                 if( sum<0 ) sum = a;
                 else sum += a;
             }else{
                 if( sum+a>0 ) sum += a;
                 else sum = a;
             }
             if( sum > max ) max = sum;
         }
         cout << max << endl;
    }

    return 0;
}

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

using namespace std;
int n,a[5008];

int solve(){
  int res=0;
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      int tmp=0;
      for(int p=i;p<=j;p++){
        tmp+=a[p];
      }
      res=max(res,tmp);
    }
  }
  return res;
}

int main(){
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
    }

    printf("%d\n",solve());

  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int n;

constexpr long long minf = -100000 * 5000;

void solve(){
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    vector<ll> sum(n+10,0);    // sum[i] = a[0] + ... + a[i-1]
    for(int i=0;i<n;i++) sum[i+1] = sum[i] + a[i]; 

    ll ans = minf-10;

    rep(i,n) rep(j,n) if(i<=j){
        // k = a[i] + ... + a[j]
        ll k = sum[j+1] - sum[i];
        ans = max(ans,k);
    }

    cout << ans << endl;
}

int main(){
    while(cin>>n){
        if(n==0) break;
        solve();
    }
}

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

int main()
{
	int n;
	while (cin >> n&&n > 0) {
		int a, maxsum = 0;
		for (int i = 0;i < n;++i) {
			cin >> a;
			if (a > 0) {
				maxsum += a;
			}
		}
		cout << maxsum << endl;
	}
}

C++: #include <bits/stdc++.h>
typedef long long LL;
#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)

using namespace std;
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    vector<int> a;
    a.resize(n+1);
    a[0]=0;
    REP(i,n) cin >> a[i+1];
    REP(i,n) a[i+1]+=a[i];
    int answer=-1048576;
    REP(i,n)REP(j,i) answer=max(answer,a[i]-a[j]);
    cout << answer << endl;
  }
}

C++: #include<iostream>
#include<vector>
int main()
{
	while (!std::cin.eof())
	{
		int n;
		std::cin >> n;
		if (n == 0)
		{
			break;
		}
		std::vector<int>a;
		for (int i = 0; i < n; i++)
		{
			int foo;
			std::cin >> foo;
			if (i == 0 || a.back() * foo < 0 || a.back() < 0 && foo == 0 || a.back() == 0 && foo < 0)
			{
				a.push_back(foo);
			}
			else
			{
				a.back() += foo;
			}
		}
		int max = -100001;
		if (a.size() == 1)
		{
			max = a[0];
		}
		else
		{
			int begin = a[0] >= 0 ? 0 : 1;
			int temp_max = a[begin];
			try
			{
				for (int i = begin;;)
				{
					if (a.at(i + 1) + a.at(i + 2) > 0)
					{
						temp_max += a[i + 1] + a[i + 2];
						i += 2;
					}
					else
					{
						if (max < temp_max)
						{
							max = temp_max;
						}
						temp_max = a[i + 2];
						i += 2;
					}
				}
			}
			catch (std::out_of_range)
			{
				if (max == -100001)
				{
					max = temp_max;
				}
			}
		}
		std::cout << "max: " << max << std::endl << std::endl;
	}
	return 0;
}

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

int main(){
int n,m=0;
int a[5001];
int sum;
int big=0;
while(cin>>n){
big=0;
for(int i=0;i<n;i++)cin>>a[i];

for(int i=0;i<n-1;i++){
if((a[i]>=0&&a[i+1]>=0)||(a[i]<=0&&a[i+1]<=0)){
a[i]+=a[i+1];
for(int j=i+1;j<n-1;j++)a[j]=a[j+1];
i--;
n--;}}

for(int i=0;i<n;i++)cout<<a[i]<<endl;

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

C++: #include <iostream>

using namespace std;

int main()
{
	int num;

	while( cin >> num ) {
		if (num == 0 )
			break;

		long int tmpnum = 0;
		long int currnum;
		long int maxnum = 0;
		for( int i = 0; i < num; i++ ) {
			cin >> currnum;

			if( currnum + tmpnum > maxnum ) {
				maxnum = currnum + tmpnum;
			}
			
			if( currnum + tmpnum > currnum )
				tmpnum += currnum;
			else
				tmpnum = currnum;
			if( tmpnum < 0 )
				tmpnum = 0;

		}
		cout << maxnum << endl;
	}
	return 0;
}

C++: #include "iostream"
using namespace std;

int a[5000],b[5001];

int main(int argc, char const *argv[])
{
	int n;
	b[0]=0;
	while(cin>>n,n)
	{
		int ma=-5000*100000;
		for (int i = 0; i < n; ++i)
		{
			cin>>a[i];
			/*if (ma<a[i])
			{
				ma=a[i];
			}*/
		}
	 	for (int i = 0; i < n; ++i)
		{
			b[i+1]=b[i]+a[i];
		}
		for (int i = 1; i <= n; ++i)
		{
			for (int j = 0; i+j <= n; ++j)
			{
				if(ma<b[i+j]-b[j])
				{
					ma=b[i+j]-b[j];
				}
			}
		}
		cout<<ma<<"\n";
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
bool same(int a,int b){
  if(a*b>=0) return true;
  return false;
}
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int d;
    int s[n];
    int count = 0,begin = 0;
    int ans;
    for(int i=0;i<n;i++){
      cin >> d;
      if(i==0) s[0] = d;
      else if(same(d,s[count])) s[count] += d;
      else{
	count++;
	s[count] = d;
      }     
    }
    if(count==0){
      cout << s[0] << endl;
      continue;
    } 
    if(s[0]<0) begin = 1;
    for(int i=begin;i<=count;i+=2){
      unsigned long long int h = s[i];
      if(i==begin) ans = s[i];
      else if(ans<h) ans = h;
      for(int j=i+1;j<=count;j++){
	h += s[j];
	if(ans<h) ans = h;
      }
    }
    cout << ans << endl;
  }
  return 0;
}