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 <cstdio>
using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int a;
		int b = 0;
		int max = -1000000;
		for(int i=0;i<n;i++){
			cin >> a;
			b += a;
			if(max<b) max = b;
		}
		cout << max << endl;
	}
}

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

int main(){
        int n,a[5010];
        while(cin>>n && n){
                for(int i=0; i<n; i++) cin >> a[i];
                long max = 0;
                for(int k = 0; k < n; k++){
                        long sum = 0;
                        for(int i=0; i<n-k; i++){
                                sum += a[i];
                        }
                        max = (max>sum)? max:sum;
                        for(int i=0; i<=k; i++){
                                sum += (a[n-k+i]-a[i]);
                                max = (max>sum)? max:sum;
                        }
                }
                cout << max << endl;
        }

}

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

int main()
{
int n,S,A ;
A=0 ;
while(1){

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++){
S=vec.at(l)-vec.at(k);
A=max(S,A) ;
}
}
cout << A << endl ;

}
}

C++: #include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<stack>
#include<set>
#include<cmath>

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

#define EPS 1e-6

using namespace std;

int main(){

   int n,a;
   while(true){


   cin >> n;
   if(n==0) break;

   vector<int>v;
   int s=0;
   v.push_back(s);

   rep(i,n){
   cin >> a;
   s+=a;
   v.push_back(s);
   }

   int m=-1000000;
   REP(i,1,n)
   REP(j,0,i-1)
   if(v[i]-v[j]>m) m=v[i]-v[j];

   cout << m << endl;

   v.clear();

   }

	return 0;
}

C++: #include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
  // ifstream cin("../test.txt");
  int n;
  while (true) {
    cin >> n;
    if (!n) break;
    vector<int> a(n);
    vector<int> sub_sum(n); // a[0] + ... + a[i]
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sub_sum[0] = a[0];
    int max_sum = -1000000000;
    for (int i = 1; i < n; i++) {
      sub_sum[i] = sub_sum[i-1] + a[i];
      max_sum = max(max_sum, sub_sum[i]);
    }
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < i; j++) {
        max_sum = max(max_sum, sub_sum[i] - sub_sum[j]);
      }
    }
    cout << max_sum << endl;
  }
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        int ret = 0;
        int tmp = INT_MIN/2;
        for(int i=0; i<n; ++i){
            int a;
            cin >> a;
            tmp = max(tmp + a, a);
            ret = max(ret, tmp);
        }
        cout << ret << endl;
    }
}

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]>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++: /*AOJ 0022*/

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

int main(){

	int n;

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

		cout<<max<<endl;

	}

	return 0;
}

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

int main(){
        int n, a[5010],b[5010];
        while(cin >> n && n){
                for(int i=0; i<n; i++) cin >> a[i];
                b[0] = 0;
                for(int i=1; i<n+1; i++){
                        b[i] = b[i-1] + a[i-1];
                }
                int max=0;
                for(int r=1; r<n+1; r++){
                        for(int i=0; i<n-r+1; i++){
                                int x = b[r+i] - b[i];
                                max = (max > x)? max : x;
                        }
                }
                cout << max << endl;
        }
}