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 <iostream>
#include <vector>
using namespace std;

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {

		int Max = -100000;

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

		a.push_back( 0 );

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		for( int i = 1; i < n - 1; i++ ) {
		
			a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

			if ( a[i] > Max ) {
				Max = a[i];
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int solve(){
	int N;
	cin >> N;
	if(!N)return 1;
	vector<int> vec(N),dp(N);
	for(int i=0;i<N;i++)cin >> vec[i];
	dp[0]=vec[0];
	for(int i=1;i<N;i++)dp[i]=max(dp[i-1]+vec[i],vec[i]);
	cout << *max_element(dp.begin(),dp.end()) << endl;
	return 0;
}
int main(){
	while(!solve()){}
	return 0;
}

C++: #include<iostream>
int n[5000];
int main(){
	while(1){
		int a;
		std::cin >> a;
		if(a==0)break;
		int dp[5000];
		for(int i = 0; i < a; ++i){
			std::cin >> n[i];
		}
		int max = 0;
		dp[0]=n[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];
			if(max < dp[i])max=dp[i];
		}
		std::cout<<max<<std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        vector<int> v(n),rui(n);
        rep(i,0,n){
            cin>>v[i];
            if(i==0)rui[0]=v[0];
            else rui[i]=rui[i-1]+v[i];
        }
    
    int ans=0;
    rep(i,1,n-1){
        rep(j,i+1,n){
           ans=max(ans,rui[j]-rui[i-1]);
        }
    }
    rep(i,0,n){
        ans=max(ans,rui[i]);
    }
    cout<<ans<<endl;
    }
    
  
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int n, k, p, m;
	bool isPlus = true;
	while (cin >> n){
		if (0 == n) break;
		vector<int> A(n, 0);
		m = INT_MIN;
		p = 0;
		for (int i = 0; i < n; ++i){
			cin >> k;
			if (m < k) m = k;
			if (0 == i){
				A[p] = k;
				isPlus = (k > 0);
			}
			else {
				if (isPlus == (k > 0)){
					A[p] += k;
				}else{
					++p;
					A[p] = k;
					isPlus = !isPlus;
				}
			}
		}
		int sum = 0;
		for (int i = 0; i <= p; ++i){
			sum += A[i];
			if (sum < 0) sum = 0;
			if (sum > m) m = sum;
		}
		cout << m << "\n";
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
while (1){
long n,dset[5000],temp=0,MINEdset[5000],max=-99999,h[5000],b=0;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                MINEdset[j]=temp;
        }
        for (int j=i;j<n;j++){
                if (max<MINEdset[j]){
                        max=MINEdset[j];
                }
        }
        h[b]=max;
        max=-99999;
        b++;
        temp=0;
}
max=-99999;
for (int i=0;i<=b;i++){
        if (max<h[i]){
                max=h[i];
        }
}
cout<<max<<endl;
}
return 0;
}

C++: #include <stdio.h>

int arr[5000];

int p14(int size) {
	int i=0;
	int j=0;
	int sum = arr[0];
	int smax = arr[0];
	
	int s = 0;
	
	for (int t=1; t<size; t++) {
		sum+=arr[t];
		
		if ( sum > smax ) {
			i = s;
			j = t;
			smax = sum;
		}
		
		if (sum+arr[t]>0) {
		} else {
			for(; s<=t; s++) {
				sum -= arr[s];
				if ( sum > smax ) {
					i = s;
					j = t;
					smax = sum;
				}
			}
		}
	}
	
	return smax;
}

int main(void) {
	while(true) {
		int n;
		scanf("%d", &n);
		if ( n==0 ) { return 0; }
		
		for(int i=0; i<n; i++) {
			scanf("%d", &arr[i]);
		}
		
		printf("%d\n", p14(n));
	}
}

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;
unsigned long long int h, m, s, ans, n, array[5000];

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

void solve(unsigned 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 <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        int data[10000]={};
        rep(i,n) cin>>data[i];
    
    
        int maxi=-999999999;
        int dp[5003][5003]={};
        rep(i,n){
            for(int j=i;j<n+1;j++){
                if(j-1>=0){
                    dp[i][j]=dp[i][j-1]+data[j-1];
                    maxi=max(maxi,dp[i][j]);
                }
            }
        }
        cout<<maxi<<endl;
    }
    return 0;
}

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

using namespace std;

int main(void){
	int Max, Num = -1, In;
	while (Num != 0){
		vector<int>	Dat;
		Max = -100002;
		cin >> Num;
		Dat.push_back(-100001);
		for (int i = 0; i < Num; i++){
			cin >> In;
			Dat.push_back(In);
		}
		for (int i = 1; i < Num + 1; i++){
			Dat[i] = max(Dat[i], Dat[i - 1] + Dat[i]);
			Max = max(Max, Dat[i]);
		}
		cout << Max << endl;
	}
	return 0;
}