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

int main(void) {
  int n, a[5001], sum, mx;
  
  while(cin>>n, n) {
    for(int i = 0; i < n; i++) cin >> a[i];
    mx=0;
    for(int i = 0; i < n; i++) {
      sum=0;
      for(int j = i; j < n; j++) {
	sum+=a[j];
	mx=max(mx, sum);
      }
    }
    cout<<mx<<endl;
  }

  return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	int n,a[5000]={0},max=0;
	while(cin>>n&&n!=0){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=1;i<=n;i++){
			for(int j=0;j<n;j++){
				int sum=0;
				for(int k=j;k<i;k++){
					sum+=a[k];
				}
				if(max<sum)max=sum;
			}
		}
		cout<<max<<endl;
		max=0;
	}
	return 0;
}

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

#define MAX_N 5000

int main(){
    int n, ans = 0, in, before;
    while(std::cin >> n, n){
        std::cin >> before;
        ans = before;
        for(int i = 1; i < n; ++i){
            std::cin >> in;
            before = std::max(in, before + in);
            ans = std::max(before, ans);
        }
        std::cout << ans << std::endl;
        ans = 0, before = 0;
    }
    return 0;
}

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

using namespace std;

int debug = 0;

int main(void){
	int n, m, i, j, k;
	int tmp, max;
	vector<int> intv;

	while(cin >> n){
		if(n == 0){
			break;
		}else{
			//ÇÝÝ
			for(i=0;i<n;i++){
				cin >> m;
				intv.push_back(m);
				if(debug) cout << "int[" << i << "] =" << intv[i] << endl; 
			}

			//vfð¸ç·
			for(i=0;i<intv.size()-1;i++){
				if((intv[i] > 0 && intv[i+1] > 0)||
					(intv[i] < 0 && intv[i+1] < 0)){
					intv[i] += intv[i+1];
					intv[i+1] = 0;
					intv.erase( remove(intv.begin(), intv.end(), 0), intv.end());
					i = 0;
				}
			}

			for(i=0;i<intv.size();i++){
				if(debug) cout << intv[i] << endl;
			}

			max = 0;
			int vsize = intv.size();
			for(i=1;i<=vsize;i++){//i:Â
				if(debug) cout << "number =" << i << endl;
				for(j=0;j<=vsize-1-i+1;j++){ //j:JnÊu
					tmp = 0;
					for(k=0;k<i;k++){
						tmp += intv[j+k];
					}
					if(debug) cout << "tmp ==" << tmp << endl;
					if(max <= tmp){
						max = tmp;
					}
				}
			}
			cout << max << endl;
			intv.clear();
		}
	}
	return 0;
}

C++: //まともに使い方を理解していないくせにincludeしまくる人間のクズ
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <set>
//#include <map>
#include <bitset>
#include <iostream>


//using namespace stdしないと表記がめんどくさいからね、仕方ないね
using namespace std;

//可読性を上げるためのdefineが仇となる典型的パターン
#define rep(i,n) for(int i = 0; i < x; i++)

//ローカル変数とグローバル変数は使い分けよう！
stack<short> x, y;
long long int ans, n, array[5000];

//関数って楽しいよね！（魔王スマイル）

void solve(long long int sum, short i){
    if(ans < sum) ans = sum;
    if(i == n) return;
    solve(sum + array[i], i + 1);
    solve(0, i + 1);
}

int main(){
    while(true){
        scanf("%lld", &n);
        if(n == 0) return 0;
        ans = 0;
        rep(i,n) scanf("%lld", &array[i]);
        solve(0, 0);
        printf("%lld\n", ans);
    }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        int ans[5050] = {0};
        for(int i = 0; i < n; i++){
            scanf("%d",&ans[i]);
        }
        long long int mx = 0;
        for(int i = 0; i < n; i++){
            long long int sum = 0;
            for(int j = i; j < n; j++){
                sum += ans[j];
                mx = max(mx,sum);
            }
        }
        printf("%lld\n",mx);
    }
	return 0;
}

C++: #include <iostream>

using namespace std;

long long int n,a[5000];

int main(){

	long long int i,j,t,tmp;

	while(cin >> n && n){

		tmp = 0;

		t = -1000000;

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

			cin >> a[i];

		}

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

			tmp += a[i];

			if(t < tmp) t = tmp;

			if(i!=n-1){

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

					tmp += a[j];

					if(t < tmp) t = tmp;

				}

			}

			tmp = 0;

		}

		cout << t << endl;

	}

	return 0;

}

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

int main(){
	int n, a;
	while(cin >> n, n){
		n++;
		vector<int> t(n);t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> a;
			t[i] = max(t[i-1]+a, a);
		}
		cout << *max_element(t.begin()+1, t.end()) << endl;
	}
	return 0; 
}

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

  int dataSets;

  while(true){
    vector<int> a;
    cin >> dataSets;
    for(int i=0;i<dataSets;i++){
      int tmpa;
      cin >> tmpa;
      a.push_back(tmpa);
      // cout << "a[" << i << "]: " << a[i] << endl;
    }

    int max=0;
    
    for(int i=0;i<dataSets;i++){
      // i+1?????£?¶?
      for(int j=0;j<dataSets-i;j++){
	int tmp=0;
	for(int k=0;k<i+1;k++){
	  tmp += a[j+k];
	  // cout << "(i,j,k): " << i << "," << j << "," << k << "  " << "a[" << j+k << "]   max:" << max << endl;
	}
	if(tmp>max){max=tmp;}
      }
    }
    
    cout << max << endl;
    
  }

  return 0;

}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

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


int main(){
	
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		
		int in[5555];
		rep(i,n)cin>>in[i];
		
		
		int ans = -10000000000;
		reps(i,1,n+1){
			
			int sum = 0;
			rep(j,i)sum += in[j];
			
			ans = max(ans,sum);
			reps(j,i,n){
				sum-=in[j-i];
				sum+=in[j];
				ans = max(ans,sum);
			}
		}
		printf("%d\n",ans);
	}
	
}

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

int main(){
  int n,tmp,ans;
  int a[5000];

  while(scanf("%d",&n) && n){
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    
    ans = a[0];
    for(int i=0;i<n;i++)
      for(int j=i;j<n;j++){
	if(i==j)tmp = a[i];
	else tmp += a[j];
	ans = max(tmp,ans);
      }
    printf("%d\n",ans);
  }
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    for(;;){
        scanf("%d",&n);
        if(n==0) break;
        vector<int> upuse(n);
        int ins;
        scanf("%d",&ins);
        upuse[0]=ins;
        int ma=ins;
        for(int i=1;i<n;i++){
            scanf("%d",&ins);
            upuse[i]=max(ins,upuse[i-1]+ins);
            ma=max(upuse[i],ma);
        }
        printf("%d\n",ma);
    }
}

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

#define MAX 5000

using namespace std;

int main(void){

	int n,a[5000];
	int wa,max;

	while(1){
		cin>>n;
		if(n==0) break;
		wa=0;
		cin>>a[0];
		max=a[0];
		for(int i=1;i<n;i++){
			cin>>a[i];
			if(max<a[i]) max=a[i];
		}
		if(max>=0){
			for(int i=n-1;i>=0;i--){
				wa+=a[i];
				if(wa<0) wa=0;
				if(wa>max) max=wa;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}