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

int main (int argc, char const* argv[]){
  int n, max1, a[5001];
  
  while(cin >> n && n!=0){
    for(int i=0;i<n;i++) cin >> a[i];
    
    max1 = a[0];
    for (int i = 0; i < n; i += 1){
      int sum = 0;
      for(int j=i;j<n;j++){
        sum += a[j];
        max1 = max(max1,sum);
      }
    }
    cout << max1 << endl;
    
  }
  
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


int n;
ll a[5000];

ll sum(int i,int j){
	ll s=0;
	rep(k,j){
		s+=a[i+k];
	}
	return s;
}

int main(){
	while(cin>>n,n!=0){
		int c=0;
		ll MAX=-1000000000000000000;
		rep(i,n) a[i]=0;
		int cou=0;
		rep(i,n){
			cou++;
			cin>>a[0];
			//cout<<"a[0]= "<<a[0]<<endl;
			if(a[0]!=0){
				break;
			}
			
		}
		//cout<<"cou= "<<cou<<endl;
		n-=cou;
			
		/*
		rep(i,n-1) cin>>a[i+1];
		c=n-1;
		*/
		rep(i,n){
			int t;
			cin>>t;
			if(a[c]*t<0){
				a[++c]=t;
			}
			else a[c]+=t;
		}
		c++;
		for(int i=1;i<=c;i++){
			rep(j,c+1-i){
				MAX=max(MAX,sum(j,i));
			}
		}
		cout<<MAX<<endl;
	}
	return 0;
}

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int v[5001];
int main(){
	int n;
	while(cin >> n,n){
		rep(i,n) cin >> v[i];
		int sum = 0 , mx = *max_element(v,v+n);
		for(int i = 0 ; i < n ; i++){
			if(sum+v[i]<0){
				sum = 0;
			}else{
				sum += v[i];
				mx = max(sum,mx);
			}
		}
		cout << mx << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int a[5001], ans = -114514;
		for (int i = 0; i < n; i++)cin >> a[i];
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			for (int j = i; j < n; j++) {
				cnt += a[j];
				if (ans < cnt)ans = cnt;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

	long long int A[5001]={0};
	long long int n,MAX = -100000;

		while(1){

			cin >> n;

			if( n == 0 ) break;

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

				cin >> A[i];
	
			}

			MAX = -100000;
		
			for(int i = 1; i <= n; i++){

				A[i] = max(A[i], A[i] + A[i-1]);
				MAX = max(A[i], MAX);

			}
	
			cout  << MAX << endl;

		}
	return 0;
}

C++: #include <iostream>
int main(){
	int n, v[5000], m;
	while(std::cin >> n, m=n){
		for(;m--;)std::cin >> v[m];

		m = *v;
		for(int i=0;i<n;i++)
			for(int j=i,k=v[i];j<n;j++,k+=v[j])
				m=k>m?k:m;

		std::cout << m << '\n';
	}	
}

C++: #include <stdio.h>

int main()
{
	int n, x, p, i, j, k;
	
	while(scanf("%d", &n) != 0){
		if (n == 0) break;

		int a[n];

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

		x = a[0];

		for(i = 1; i <= n; i++){
			for(j = 0; j < n-i+1; j++){
				p = 0;

				for(k = 0; k < i; k++){
					p += a[j+k];
				}

				if(x < p) x = p;
			}
		}

		printf("%d\n", x);
	}

	return 0;
}

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

int main()
{
	int a,max_ret=0;
	while(1){
		cin>>a;
		if(a==0){
			return 0;
		}
		int n[5000];
		for(int i=0;i<a;i++){
			cin>>n[i];
		}
		int dp[5000];
		dp[0] = n[0];
		int Max=0;
		for(int i=1;i<a;i++){
			if(dp[i-1]>0){
				dp[i] = dp[i-1] + n[i];
			}else{
				dp[i] = n[i];
			}
			max_ret = max( dp[i], Max);
		}
		
		cout<<max_ret<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    while(cin >> n, n){
        vector<int> a(n, 0), sum(n + 1, 0);
        rep(i, 0, n){
            cin >> a[i];
        }
        rep(i, 1, n + 1){
            sum[i] += sum[i - 1] + a[i - 1];
        }
        int MAX = -1e10;
        rep(i, 0, n + 1){
            rep(j, i + 1, n + 1){
                MAX = max(MAX, sum[j] - sum[i]);
            }
        }
        cout << MAX << endl;
    }
}

C++: #include<iostream>

using namespace std;

int main(){
	int n;	
	while (true) {
		cin >> n;
		if (n != 0) {
			int *num = new int[n];
			for (int i = 0; i < n; i++) {
				cin >> num[i];
			}
			/*最大を更新していきたい*/
			int max_v = -999999999;
			for (int i = 0; i < n; i++) {
				int j = i, tmp_total = 0;
				for (j; j < n; j++) {
					tmp_total += num[j];
					if (tmp_total > max_v) {
						max_v = tmp_total;
					}

				}
			}
			cout << max_v << endl;

		}
		else if(n==0){
			break;
		}

	}
	return 0;
}

C++: /*Filename: aoj0022.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

int main(){
	int n = 0;

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

        int a[n];
        for(int i = 0; i < n; ++i){
        	cin >> a[i];
        }

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

        int maxSum = INT_MIN;
        int minSum = 100000 * 5000 + 1;
        for(int i = 0; i < n; ++i){
        	maxSum = max(maxSum, sum[i] - minSum);
        	minSum = min(minSum, sum[i]);
        }
        
        cout << maxSum << endl;
    }

	return 0;
}

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

int main(){
int n,Sum,Ans ;

while(1){

Ans=0 ;

cin >> n ;

if(n==0){
break ;
}

vector<int> vec(n+1,0) ;

for(int i=1;i<n+1;i++){
cin >> vec.at(i) ;
}

for(int j=0;j<n;j++){
vec.at(j+1)=vec.at(j)+vec.at(j+1) ;
}

for(int k=0;k<n+1;k++){
    for(int l=k;l<n+1;l++){
    Sum=vec.at(l)-vec.at(k);
    Ans=max(Sum,Ans) ;
    }
}
cout << Ans << endl ;

}
}

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

int main(){
	int n, max1, max2, a[5001];

	while( cin >> n , n ){
		for(int i=0 ; i<n ; i++){
			cin >> a[i] ;
		}
		max1 = a[0];

		for(int i=0 ; i<n ; i++){
			int sum = 0;
			for(int j=i ; j<n ; j++){
				sum += a[j];
				max1 = max( max1 , sum );
			}
		}
		cout << max1 << endl;
	}

C++: #include<iostream>
main(){int n,v[5000],m;while(std::cin>>n,m=n){for(;m--;)std::cin>>v[m];m=*v;for(int i=0;i<n;i++)for(int j=i,k=v[i];j<n;j++,k+=v[j])m=k>m?k:m;std::cout<<m<<'\n';}}