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

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<string>
#include<math.h>
typedef long long LL;
using namespace std;
int main()
{
  //  freopen("test.txt", "r", stdin);
  //  freopen("testout.txt", "w", stdout);
    int n=0;
    LL x,max_sum,cur_sum;
    while(~scanf("%d",&n)&&n)
    {
        x=0;
        cur_sum=0;
        max_sum=-99999999;
        while(n--)
        {
            cin>>x;
            cur_sum+=x;
            if(max_sum<cur_sum)
                max_sum=cur_sum;
            if(cur_sum<0)
                cur_sum=0;
        }
        cout<<max_sum<<endl;
    }
    return 0;
}

C++: #include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
	int n;while(cin>>n,n){
	int a[5000];
	rep(i,n)cin>>a[i];
	int ans=-10000000,sum;
	rep(i,n)
	{
		sum=0;
		for(int j=i;j<n;j++)
		{
			sum+=a[j];
			ans=max(ans,sum);
		}
	}
	cout<<ans<<endl;}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	long int n, m[5000] = { 0 }, max = 0, temp = 0;
	int out;
	
	while (cin>> n && n!=0){
		for (int i = 0; i < n; i++){
			cin >> m[i];
		}
		for (int i = 0; i < n; i++){
			temp = m[i];
			for (int l = i + 1; l < n; l++){
				temp += m[l];
				if (max < temp){
					max = temp;
				}
			}temp = 0;
		}
		cout << max << endl;
		max = 0;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n, sum[5001] = {};
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      int a;
      cin >> a;
      sum[i + 1] = sum[i] + a;
    }
    int ret = sum[1];
    for(int i = 0; i <= n; i++){
      for(int j = i + 1; j <= n; j++){
        ret = max( ret, sum[j] - sum[i]);
      }
    }
    cout << ret << endl;
  }
}

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

using namespace std;
int dp[5001];

void solve()
{
	int n;
	while(cin >> n, n)
	{
		for(int i = 0; i < 5001; ++i)
		{
			dp[i] = -999999999;
		}
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		int Max = -999999999;
		dp[0] = Vec[0];
		int sum = Vec[0];
		for(int i = 1; i < n; ++i)
		{
			if(sum + Vec[i] < Vec[i])
			{
				dp[i] = Vec[i];
				sum = Vec[i];
			}
			else
			{
				dp[i] = sum + Vec[i];
				sum += Vec[i];
			}
			if(dp[i] < dp[i - 1])
			{
				dp[i] = dp[i - 1];
			}
		}
		cout << dp[n - 1] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int main(){
	int n,p,m;
	int number[5000];
	int sum=0,max=0;

	scanf("%d",&n);

	while(n != 0){
		memset(number,'\0',sizeof(number));
		for(int i=0;i<n;i++){
			cin >> p;
			number[i] = p;
		}

		for(int i=0;i<n;i++){
			m = n;
			while(0 < m){
				for(int j=m-1;j>=i;j--){
					sum += number[j];
				}
				m--;
				if(sum > max){
					max = sum;
				}
				sum = 0;
			}
			m=n;
		}
		cout << max << endl;

		sum = max = 0;
		scanf("%d",&n);
	}
}