Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

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

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;

ll ara[10000];
int main()
{
    ll n;
    while(scanf("%lld", &n))
    {
        if(n==0) break;
        for(ll i=1; i<=n; i++){
            scanf("%lld", &ara[i]);
        }

        ll p = 0;
        for(ll i = 1; i <= n; i++){
            ll s = 0;
            for(ll j = i; j <= n; j++){
                s += ara[j];
                p = max(p,s);
            }
        }
        printf("%lld\n", p);
    }

    return 0;
}

C++: #include <stdio.h>
main(){
  int i,n,j,sum,big=-3000000,a[n];
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
      sum=0;
      for(j=i;j<n;j++){
	sum+=a[j];
	if(sum>big){
	  big=sum;
	}
      }
    }
    printf("%d\n",big);
  }
  return 0;
}