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 <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000001
#define IN_MAX -223372036854775808

using namespace std;
#define ll long long
#define dbg if(0)



int main(){
    while(true){
        int n;
        ll ans= IN_MAX;
        cin>>n;
        if (n==0)break;

        ll rui[n+1];
        rui[0]=0;
        for(int i=1;i<=n;i++){
            cin >>rui[i];
            rui[i]+=rui[i-1];
            dbg cout <<rui[i]<<" ";
        }
        //次を見る
        //今までの最小値を更新したか？
        //したなら暫定解を確定しansと比較。最大値=最小値=発見した最小値にする
        //してなければ最大値の更新をする
        //見る場所が一番後ろまで行ったら終了。
        ll nmin=rui[0],nmax=rui[0];
        for(int i=0;i<=n;i++){
            if (rui[i]<nmin){
                ans=max(nmax-nmin,ans);
                nmax=rui[i];
                nmin=rui[i];
            }else{
                if(rui[i]>nmax){
                    nmax=rui[i];
                }
            }
            dbg cout <<nmax<<" "<<nmin<<endl;
        }
        ans=max(nmax-nmin,ans);
        dbg cout << endl;
        cout<<ans<<endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <climits>
using namespace std;
#define rep2(i,from,to) for(int i=(from); i<(to); ++(i))
#define rep(i,to) rep2(i,0,to)
int main() {
	int n;
	while(cin >> n && n) {
		int a[5001];
		int Max = INT_MIN;
		rep(i,n) {
			cin >> a[i]; 
		}
		rep(i,n) {
			int sum = 0;
			rep2(j,i,n) {
				sum += a[j];
				Max = max(Max, sum);
			}
		}
		cout << Max << endl;
	}
	return 0;
}

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

C++: #include <iostream>
#define MAX(a,b) (((a)>(b))?(a):(b))

using namespace std;
typedef long long int lli;
int main(void){
	int n;
	lli a[5000];
	while(cin>>n,n){
		for(int i=0;i<n;i++)cin>>a[i];
		lli max=-2000000;
		lli sum=0;
		lli msum=0;
		bool isminus=false;
		int t=0;
		max=a[0];
		if(a[0]>=0) sum+=a[0];
		for(int t=1;t<n;t++){
			// cout<<"debug:"<<max<<" "<<sum<<" "<<msum<<endl;
			if(a[t]>=0){
				if(!isminus){ // ??£????????£
					sum+=a[t];
					max=MAX(sum,max);
				}
				else { // ???????????£
					isminus=false;
					if(sum+msum>=0){ // ????????????????¨?????????????????????´???
						max=MAX(sum,max);
						sum+=msum;
						sum+=a[t];
						msum=0;
					}else{ // ???????????£??§??????????????????????????´???
						max=MAX(sum,max);
						sum=0;
						sum+=a[t];
						msum=0;
					}
				}
			}else{
				if(isminus)msum+=a[t];
				else{
					isminus=true;
					msum+=a[t];
				}
			}
		}
		cout<<MAX(sum,max)<<endl;
	}
	return 0;
}

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

int a[5001];

int sumation(int i, int n){
	int res=0;
	for(int k=0; k<n; k++){
		res += a[i+k];
	}
	return res;
}

int main(void){

	for(int i=0; i<5001; i++) a[i] = 0;

	int n;
	while(cin >> n){
		
		if(n==0) break;
		for(int i=0; i<n; i++){
			int tmp;
			cin >> tmp;
			a[i] = tmp;
		}

		int res = 0;
		for(int i=1; i<=n; i++){	
			int rres = 0;
			for(int j=0; j<(n-i+1); j++){	
				if( rres < sumation(j,i) ) rres = sumation(j,i);
			}
			if( res < rres ) res = rres;
		}
		cout << res << endl;

		for(int i=0; i<5001; i++) a[i] = 0;
	}

	return 0;
}

C++: #include <iostream>


using namespace std;




int main(){
	

	int n;
	int a[5000];
	int max;
	int temp;
	
	while(cin>>n&&n){
	for(int i=0;i<n;i++)cin>>a[i];
	max=a[0];
	
	for(int i=0;i<n;i++){
		temp=0;
		for (int j=i; j<n; j++) {
			temp+=a[j];
		
		if (max<temp) {
			max=temp;
		}
		}
	}
	
	
	cout << max <<endl;
	}
		
	return 0;
}

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

int main() {
	int n;
	long max, sum, ans;
	while (true) {
		cin >> n;
		if (n == 0) break;
		vector<int> array(n);
		for (int i = 0;i < n;i++) {
			cin >> array[i];
		}

		for (int j = 0;j < n - 1;j++) {
			max = array[j] + array[j + 1];
			sum = array[j];
			for (int i = j + 1;i < n;i++) {
				sum += array[i];
				if (sum > max) {
					max = sum;
				}
			}
			if (j == 0) {
				ans = max;
			}
			else if (max > ans) {
				ans = max;
			}
		}
		if (array[n - 1] > ans) {
			ans = array[n - 1];
		}


		cout << ans << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MIN (-(1<<20))
vector<int> dp(5001);
vector<int> v(5001);
int main()
{
	int n;
	while (true) {
		cin >> n;
		if (n == 0) break;
		fill(dp.begin(), dp.end(), MIN);
		for (int i = 0; i < n; ++i) cin >> v[i];
		dp[0] = v[0];
		for (int i = 1; i < n; ++i)
			dp[i] = max(v[i], dp[i-1] + v[i]);
		sort(dp.begin(), dp.begin() + n);
		cout << dp[n-1] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<functional>
using namespace std;
int main(){
	int n;
	while(cin >> n){
		if(n==0) break;
		vector<int> a;
		vector<int> s;
		for(int i=0;i<n;++i){
			int t;
			cin >> t;
			a.push_back(t);
		}
		for(int i=0;i<a.size();++i){
			for(int j=i+1;j<=a.size();++j){
				s.push_back(accumulate(a.begin()+i,a.begin()+j,0));
			}
		}
		sort(s.begin(),s.end(),greater<int>());
		cout << s[0] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<functional>
using namespace std;
int main(){
	int n;
	while(cin >> n){
		if(n==0) break;
		vector<int> a;
		vector<int> s;
		int sum=0;
		for(int i=0;i<n;++i){
			int t;
			cin >> t;
			a.push_back(t);
		}
		for(int i=0;i<a.size();++i){
			for(int j=i+1;j<=a.size();++j){
				s.push_back(accumulate(a.begin()+i,a.begin()+j,0));
			}
		}
		stable_sort(s.begin(),s.end(),greater<int>());
		cout << s[0] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
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 >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}*/
		for(int i = 1;i < n;i++){
			cin >> a;
			t[i] = max(t[i-1]+a, a);
		}
		cout << *max_element(t.begin(), t.end()) << endl;
	}
	return 0; 
}

/*
7
-5
-1
6
4
9
-6
-7
*/

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

int main()
{

	int n, num;
	vector< long int > a;
	vector< long int > res;

	while( 1 ) {

		int Max = -INT_MAX;

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

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

		//?????§???
		for( int i = 1; i < n; 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];
			}
		
		}

		res.push_back( Max );
		a.clear();
	
	}

	for( vector< long int > :: iterator mIt = res.begin(); mIt != res.end(); ++mIt ) {
		cout << *mIt << endl;
	}

	return 0;

}