Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

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

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