Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

C++: #include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <cmath>
#include <sstream>
#define F first
#define S second
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int main() {
	int n;
	while (cin >> n && n) {
		long long a[6000];
		a[0] = 0;
		for (int l = 0; l < n; l++) {
			cin >> a[l + 1];
		}
		for (int l = 1; l <= n; l++) {
			a[l] += a[l - 1];
		}
		long long ans = 0;
		for (int l = 0; l < n; l++) {
			for (int r = l + 1; r <= n; r++) {
				ans = max(ans, a[r] - a[l]);
			}
		}
		cout << ans << endl;
	}




	return 0;
}

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

int main(){
	const int nmax = 5001;
	int n;
	int nums[nmax];
	while(cin >> n){
		if(n == 0) break;
		int a;
		for(int i = 1;i <= n; i++){
			cin >> a;
			nums[i] = a;
		}
		int total_max = 0;
		for(int i = 1; i <= n; i++){
			int total = 0;
			for(int j = i; j <= n; j++){
				total += nums[j];
				total_max = max(total_max, total);
			}
		}
		cout << total_max << endl;
	}
	return 0;
}

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

int main()
{
	int n, a[5000], i, j, k, l, sum, max;

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

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

		max = -2147483647 - 1;
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n - i; j++)
			{
				for (k = 0; k < n - i; k++)
				{
					sum = 0;
					for (l = k; l <= i; l++)
						sum += a[l];
					if (sum > max) max = sum;
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
const int MAX_N = 5000;
using namespace std;

int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0) break;
    int dp[MAX_N];
    cin >> dp[0];

    int max_num = dp[0];
    for (int i = 1; i < n; i++) {
      int tmp;
      cin >> tmp;
      dp[i] = max(dp[i-1]+tmp, tmp);
      max_num = max(max_num, dp[i]);
    }

    cout << max_num << endl;
  }
  return 0;
}

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