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>

using namespace std;

#define N 2<<30;

int main(){

  int n;


  while(cin >> n){
    if(n == 0) break;
    vector<int> V;
    int status;
    int in;
    int sum = 0;
    for(int i = 0; i < n; i++){
      cin >> in;
      if(i == 0){
	if(in < 0) status = -1;
	else if(in >= 0)status = 1;

      } else {

	if(in < 0 && status > 0){
	  status = -1;
	  V.push_back(sum);
	  sum = 0;
	  V.push_back(in);
	}else if(in < 0 && status < 0){
	  V.push_back(in);
	}else if(in >= 0 && status < 0){
	  status = 1;
	  V.push_back(sum);
	  sum = 0;
	}
      }
      sum += in;
      if(sum < 0) sum = 0;
    }
    if(sum != 0) V.push_back(sum);

    int max = -1*N;
    
    for(int i = 0; i < V.size(); i++){
      sum = 0;
      for(int j = i; j < V.size(); j++){
	sum += V[j];
	if(max < sum) max = sum;
      }
    }
    
    cout << max << endl;
  }
  return 0;
}

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

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> num(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> num[i];
		}
		vector<int> memo(n);
		memo[0] = num[0];
		for(int i = 1; i < n; ++i)
		{
			if(memo[i - 1] + num[i] > num[i])
			{
				memo[i] = memo[i - 1] + num[i];
			}
			else
			{
				memo[i] = num[i];
			}
		}
		int max_num = 0;
		for(int i = 0; i < n; ++i)
		{
			if(max_num < memo[i])
			{
				max_num = memo[i];
			}
		}
		cout << max_num << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int main(){
    int n;
    while(cin >> n && n){
        vector<int> a(n,0);
        for(int i=0; i<n; ++i){
            cin >> a[i];
        }
        // ????????£?¶??????????????????§??£?¶???????dp??¨?????????
        vector<int> dp(n,0);
        dp[0] = a[0];
        int max = dp[0];
        for(int i=1; i<n; ++i){
            if(dp[i-1]>0){
                dp[i] = dp[i-1] + a[i];
            } else {
                dp[i] = a[i];
            }
            if(max<dp[i]){
                max = dp[i];
            }
        }
        cout << max << endl;
    }
}

C++: #include<stdio.h>
main(){
	int i,j,n,a[5000];
	
	int sum = 0,max = 0,ans = 0;
	
	
	while(1){
		
		max = 0;
	
		scanf("%d",&n);
		
		if(n==0) break;
		
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		
		for(i = n - 1; (i >= 0)&&(a[i] <= 0); i--);
		
		n = i;
		
		for(i = 0; a[i] <= 0; i++);

		
		for( ;i <= n; i++){
			
			sum = 0;
			
			for(j = i; j <= n; j++) sum += a[j];
			
			max = sum;
			
			for(j = n; j >= i; j--){
				
				sum -= a[j];
				
				if(sum > max) max = sum;
				
			}
			
			if(max > ans ) ans = max;
		}

		printf("%d\n",ans);
		
		
		sum = 0;
		max = 0;
		ans = 0;
		
	}

	return 0;
}

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

int main(){
  int n;
  int a[5000];
  while(cin >> n && n>0){
    for(int i=0;i<n;i++)
      cin >> a[i];
    long long sum=0,tmp=0,ma=-100000;
    int m=-100000;
    bool flg=true;
    for(int i=0;i<n;i++){
      if(flg) m=max(m,a[i]);
      if(a[i]>0){
	flg=false;
	sum+=a[i];
	continue;
      }
      ma=max(ma,sum);
      for(tmp=sum;i<n && a[i]<=0;i++){
	tmp+=a[i];
      }i--;
      if(tmp>0)
	sum=tmp;
      else
	sum=0;
    }
    ma=max(ma,sum);

    cout << (flg?m:ma) << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

using namespace std;

long int a[5000],ma,n;

int main()
{
	
	while(cin >> n, n)
	{
		ma = 0;
		
		for( int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		
		for( int j = 0; j < n; j++)
		{
			int sum = 0;
			
			for( int i = j; i < n; i++)
			{
				sum += a[i];
				
				if( sum > ma )
					ma = sum;
				
			}
		}
		
		cout << ma << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> Pi;

const int INF=100000000;
const long long int INF_=1000000000000000000;

int main(){
	int N;
	while(cin >> N&&N){
		vector<int> A(N);
		REP(i,0,N) cin >> A[i];
		vector<int> s(N);
		s[0]=A[0];
		REP(i,1,N) s[i]=s[i-1]+A[i];
		lli ans=-INF_;
		REP(i,0,N) REP(j,i+1,N) if(ans<s[j]-s[i]) ans=s[j]-s[i];
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		int sum=0,a[5001],ans=0;
		vector<int>anss(0);
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++){
			sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				ans=max(sum,ans);
				//anss.push_back(sum);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  vector<int>in(5000);
  while(cin>>n,n){
    rep(i,n)cin>>in[i];
    int max=0;
    rep(i,n){
      int sum=0;
      loop(j,i,n){
	sum+=in[j];
	if(max<sum)max=sum;
      }
    }
    cout<<max<<endl;
  }


}

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

using std::cin;

int main()
{

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

        std::vector<int> line(n);
        for (auto i = 0; i < n; i++) {
            int in;
            cin >> in;
            line.at(i) = in;
        }

        int max = -100000;
        for (auto i = 0; i < n; i++) {
            int sum_ij;
            int max_i;
            max_i = sum_ij = line.at(i);
            for (auto j = i + 1; j < n; j++) {
                sum_ij += line.at(j);
                if (sum_ij > max_i) {
                    max_i = sum_ij;
                }
            }
            if (max_i > max) {
                max = max_i;
            }
        }

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

    return 0;
}