Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

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

C++: #include<cstdio>
#include<vector>
#include<deque>
using namespace std;
int main(){
    int n;
    for(;;){
        scanf("%d",&n);
        if(n==0) break;
        vector<int> numa(n);
        deque<int> suma;
        int ans=0;
        for(int i=0;i<n;i++){
            scanf("%d",&numa[i]);
        }
        
        bool isplus=numa[0]>=0;
        int nowsum=numa[0];
        for(int i=1;i<n;i++){
            if((numa[i]>=0) == isplus){
                nowsum+=numa[i];
            }else{
                isplus=numa[i]>=0;
                suma.push_back(nowsum);
                nowsum=numa[i];
            }
        }
        suma.push_back(nowsum);

        if(suma.front()<0){
            if(suma.size()==1){
                int m=0;
                for(int i=0;i<n;i++){
                    if(m==0 || m<numa[i]) m=numa[i];
                }
                ans=m;
            }
            suma.pop_front();
        }else if(suma.size()==1){
            for(int i=0;i<n;i++){
                ans+=numa[i];
            }
        }

        while(!suma.empty()){
            if(suma.size()>=3){
                nowsum=suma.front();
                suma.pop_front();
                while(suma.size()>=2 && suma[0]+suma[1]>0){
                    nowsum+=suma[0]+suma[1];
                    suma.pop_front();
                    suma.pop_front();
                }
                if(suma.size()>0) suma.pop_front();
                if(ans<nowsum) ans=nowsum;
            }else if(suma.size()==2){
                if(ans<suma[0]) ans=suma[0];
                suma.pop_front();
                suma.pop_front();
            }else if(suma.size()==1){
                if(ans<suma[0]) ans=suma[0];
                suma.pop_front();
            }
        }
        printf("%d\n",ans);
    }
}

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

int main(){
	int n;
	int a;
	int result;
	cin >> n;
	while(n){
		for(int i=0;i<n;i++){
			cin >> a;
			if(a > 0){
				result += a;
			}
		}
		cin >> n;
	}
	return 0;
}