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

int n, m, a, p, q;

int main()
{
	cin >> n;

	while (n > 0) {
		m = 0;
		p = -200000;
		q = 0;

		for (int i = 0; i < n; i++) {
			cin >> a;

			m += a;
			p = max(p, m - q);
			q = min(q, m);
		}

		cout << p << endl;
		cin >> n;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;

ll dp[5000];
int main(){
	int n,a;
	while(1){cin >> n;if(!n)break;
		ll ans=0;
		memset(dp,0, sizeof(dp));
		rep(i,n){cin>>a;
			if(dp[i-1]>0)dp[i]=dp[i-1]+a;
			else dp[i] = a;
			ans = max(ans,dp[i]);
		}
		cout<<ans<<endl;
	}

}

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

int main(){
    int n;
    while(scanf("%d",&n) && n != 0){
        int arr[n];
        for(int i = 0; i < n; i++){
            scanf("%d",&arr[i]);
        }
        int max_e = 0, max_s = 0;
        for(int cur = 0; cur < n; cur++){
            max_e = max(arr[cur], max_e + arr[cur]);
            max_s = max(max_s, max_e);
        }
        printf("%d\n",max_s);
    }
}

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

int main(){
	int n;
	cin >> n;
	while(n != 0){
		int a[n];
		

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

		int maximum = 0;
		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = i; j < n; j++){
				sum += a[j];
				maximum = max(maximum, sum);
			}
		}

		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}

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

int main(){
	long long int n;
	
	while(cin>>n,n){
		long long int max=0;
		long long int sum[n];
		for(int i=0;i<n;i++){
			long long int num;
			cin>>num;			
			sum[i]=num;
			for(int j=0;j<i;j++){sum[j]+=num;if(max<sum[j])max=sum[j];}
		}
		cout<<max<<endl;
	}
}

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

using namespace std;

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

	int max = a[0];
	for(int i=0;i<n;i++){
	  int sum = 0;
	  for(int j=i;j<n;j++){
		sum += a[j];
		if(max < sum) max = sum;
	  }
	}
	
	cout << max << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

long long  n, a[5010], memo[5010];
const long long INF = -(1<<20);
void solve(){
  memo[0] = max(INF, a[0]);
  long long ans = INF;
  for(int i = 1 ; i < n ; i++){
    memo[i] = max(memo[i], max(memo[i-1]+a[i], a[i]));
    ans = max(memo[i], ans);
  }
  cout << ans << endl;
}
int main(){

  while(cin >> n, n){
    fill(memo, memo+n, INF);
    for(int i = 0 ; i < n ; i++){
      cin >> a[i];
    }
    solve();
  }
  return 0;
}

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

int main()
{
	int n = 1, count = 0;
	int a[10000];
	while (n != 0) {
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = -10000;
		for (int ai = 0; ai < n - 1; ai++) {
			sum = 0;
			for (int bi = ai; bi < n; bi++) {
				sum = sum + a[bi];
				if (sum > max) {
					max = sum;
				}
			}
		}
		if (n != 0)
			cout << max << endl;
	}
}

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

 int main()
 {
     while(1){
         int n;
         cin >> n;
         if( !n ) break;

         int a;
         long long  max = numeric_limits<long long>::min();
         long long  sum = numeric_limits<long long>::min();
         for(int i=0; i<n; i++){
             cin >> a;

             if( max<0 && a<0 && max<a ) { max = a; continue; }
             else if( max<0 && a<0 && max>a){ continue; }

             if( a>0 ){
                 if( sum<0 ) sum = a;
                 else sum += a;
             }else{
                 if( sum+a>0 ) sum += a;
                 else sum = a;
             }
             if( sum > max ) max = sum;
         }
         cout << max << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int64_t dp[5001][5001];
int main(){
	while(true){
		int64_t ans=1,bans=1;
		int n;
		cin>>n;
		if(n==0){
			break;
		}
		int64_t a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int j=1;j<=n;j++){
			for(int k=j;k<=n;k++){
				dp[j][k]=dp[j][k-1]+a[k-1];
				if(dp[ans][bans]<dp[j][k]){
					ans=j;
					bans=k;
				}
			}
		}
		cout << dp[ans][bans] << endl;
	}
}
// a[n]={1,2,3,100,200};
// dp[n]={1, 1+2, 1+2+3, 1+2+3+100, 1+2+3+200};

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;
	bool first = 0, notAllMinus=0;
	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; 
			}

			//SÌêÌ»è
			tmp = intv[0];
			for(i=0;i<intv.size();i++){
				if(intv[i] > 0){
					notAllMinus = 1;
					break;
				}else{
					if(tmp < intv[i]){
						tmp = intv[i];
					}
				}
			}

			if(notAllMinus == 0){
				cout << tmp << endl;
				continue;
			}

			//vfð¸ç·
			tmp=0;
			for(i=1;i<intv.size();i++){
				if(intv[tmp] > 0){
					if(intv[i] > 0){ //¯Èç
						intv[tmp] += intv[i];
						intv[i] = 0;
					}else{ //ÙÈç
						tmp = i;
					}
				}else if(intv[tmp] < 0){
					if(intv[i] < 0){
						intv[tmp] += intv[i];
						intv[i] = 0;
					}else{
						tmp = i;
					}
				}
			}
			/*
			if(debug){
				for(i=0;i<intv.size();i++){
					cout << intv[i] <<endl;
				}
				cout << "----------------------" << endl;
			}
			*/
			intv.erase( remove(intv.begin(), intv.end(), 0), intv.end());
			/*
			if(debug){
				for(i=0;i<intv.size();i++){
					cout << intv[i] <<endl;
				}
			}
			*/

			int vsize = intv.size();
			for(i=1;i<=vsize;i+=2){//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(first == false){
						max = tmp;
						first = true;
					}else if(max < tmp){
						max = tmp;
					}
				}
			}
			cout << max << endl;
			intv.clear();
			first = false;
			notAllMinus = 0;
		}
	}
	return 0;
}