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<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n;
    while(cin>>n,n){
        ll a[5010];
        ll dp[5010];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        ll ans=-LINF;
        for(int j=0;j<n;j++){
            if(dp[j]<0){
                dp[j+1]=a[j];
            }else{
                dp[j+1]=dp[j]+a[j];
            }
            ans=max(dp[j+1],ans);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

using namespace std;

inline int max (int a, int b) {
    return a > b ? a : b;
}

int main (void) {
    int n, i, j;
    while (1) {
        cin >> n;
        if (n == 0) break;
        int a[n];
        for (i = 0; i < n; i++) {
            cin >> a[i];
        }
        int sum = INT_MIN, s;
        for (i = 0; i < n; i++) {
            s = 0;
            for (j = i; j < n; j++) {
                s += a[j];
                sum = max(sum, s);
            }
        }
        cout << sum << endl;
    }
    return 0;
}

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;
		}
		cout << maxnum << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int arr[5000];

int p14(int size) {
	int i=0;
	int j=0;
	int sum = 0;
	int smax = -10000000;
	
	int s = 0;
	
	for (int t=0; t<size; t++) {
		sum+=arr[t];
		
		if ( sum > smax ) {
			i = s;
			j = t;
			smax = sum;
		}
		
		if (sum < 0 ) {
			for(; s<t; s++) {
				sum -= arr[s];
				if ( sum > smax ) {
					i = s;
					j = t;
					smax = sum;
				}
			}
		}
	}
	
	printf("%d-%d  sum: %d\n", i, j, smax);
	return smax;
}

int main(void) {
	while(true) {
		int n;
		scanf("%d", &n);
		if ( n==0 ) { return 0; }
		
		for(int i=0; i<n; i++) {
			scanf("%d", &arr[i]);
		}
		
		printf("%d\n", p14(n));
	}
}

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

int main(){
	int n, max, sum, a[5001];

	while( cin >> n ){
		if(n==0) break;
		max = 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];
				max = (sum>max)? sum : max;
			}
		}
		cout << max << endl;
	}
}

C++: #include <iostream>
using namespace std;
int main(void){

	int n, max=0;
	int *a;
	int *sum;

	do{
		max = 0;
		//cout << endl;
		cin >> n;

		if (n == 0) break;

		a = new int[n];
		sum = new int [n];

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++) sum[i] = 0;
		}

		for (int i = 0; i < n; i++){

			cin >> a[i];

			for (int j = i; j >= 0; j--){

				sum[i] += a[j];
				if (max < sum[i]) max = sum[i];
			}
		}

		cout << max << endl;
	} while (1);
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
        vi v(n+1,0);
        rep(i,n)cin>>v[i];
        ll ans=v[0], temp;
        for(int i=0;i<n;i++){
            temp=v[i];
            for(int j=i+1;j<n;j++){
                temp+=v[j];
                ans=max(ans,temp);
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include <stdio.h>

int gets(int d){
	return d >= 0 ? 1 : -1;
}

int seqsum(int n){
	int a = 0;
	int b[5000];
	int c = 0;
	int s = 0;
	int f = 0;

	scanf("%d", &a);
	b[0] = a;
	f = a;
	s = gets(a);

	for(int i=1; i<n; ++i){
		scanf("%d", &a);
		if(s == gets(a)){
			b[c] += a;
		}else{
			b[++c] = a;
			s = gets(a);
		}
	}

	int m = b[0];
	int sum = m;
	for(int i=1; i<=c; ++i){
		if(sum < 0 && m < b[i]){
			sum = m = b[i];
		}else{
			sum += b[i];
			if(m < sum){
				m = sum;
			}
		}
	}
	return m > f ? m : f;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  while(cin>>n,n){
    vector<int> a(n+1);
    LOOP(i,1,n+1)cin>>a[i];
    LOOP(i,1,n+1)a[i+1]+=a[i];
    int ans=-INF;
    LOOP(i,1,n+1){
      LOOP(j,0,i){
        ans=max(ans,a[i]-a[j]);
      }
    }
    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];
		}

		int maximum = -100000000;
		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = i; j < n; j++){
				sum += a[j];
				maximum = max(maximum, sum);
			}
		}

		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[5000];
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int best=0;
	for(int lon=1;lon<=n;lon++){
		for(int first=0;first+lon<=n;first++){
			int count=0;
			for(int k=0;k<lon;k++)
				count+=a[first+k];
			if(count>best)
				best=count;
		}
	}
	cout<<best<<endl;
	}
	return 0;
}

C++: /*AOJ 0022*/

#include<iostream>
#include<vector>
using namespace std;

int main(){

	int n;

	vector<int> ansMax;

	for(;;){

		cin>>n;

		if(n==0){
			break;
		}

		vector<int> data;
		int max=0;
		int sum=0;

		for(int i=0;i<n;i++){

			int tmp;
			cin>>tmp;

			data.push_back(tmp);

		}

		for(int i=0;i<n;i++){
			sum = 0;
			if(data.at(i)<0){
				continue;
			}
			for(int j=i;j<n;j++){
				sum+=data.at(j);
				if(sum>=max){
					max = sum;
				}
			}
		}
		data.clear();

		ansMax.push_back(max);

	}

	for(int i=0;i<ansMax.size();i++){
		cout<<ansMax.at(i)<<endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    int n=0,a[5000],saidai=-100000,kazu;
    while(cin>>n && n!=0){
saidai=-100000;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++){
            kazu=0;
            for(int x=i;x<n;x++){
                kazu=kazu+a[x];
                if(saidai<kazu){
                    saidai=kazu;
                }
            }
        }
        cout<<saidai<<endl;
    }
}