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

int main()
{
	int N;
	while(cin>>N && N){
	
		vector<int> n(N), dp(N);
		for(int i=0;i<N;i++){
			cin>>n[i];
		}
		int ans = -1<<29;
		for(int i=0;i<N;i++){
			if(i-1 >= 0 && dp[i-1]>0){
				dp[i] += dp[i-1] + n[i];
			}else{
				dp[i] = n[i];
			}
			ans = max(ans, dp[i]);
		}
		
		cout<<ans<<endl;
	}
	
	
	return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
int n,dset[5000],temp=0,MINEdset[5000],max=0,h[5000],b=0;
while (1){
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=0;
        b++;
        temp=0;
}
max=-9999999;
for (int i=0;i<b;i++){
        if (max<h[i]){
                max=h[i];
        }
}
cout<<max<<endl;
}
return 0;
}

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

using namespace std;

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        queue<int> q;
        int ans = -100000;
        int sump = 0, sumn = 0;
        while(N--) {
            int n;
            cin >> n;
            q.push(n);
            if(n >= 0) sump += n;
            else sumn += -n;
            while(q.size() > 1 && (sump <= sumn || q.front() < 0)) {
                int np = q.front();
                if(np >= 0) sump -= np;
                else sumn -= -np;
                q.pop();
            }
            ans = max(ans, sump-sumn);
        }
        cout << ans << endl;
    }
    return 0;
}

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

int maximum_sum_seq(vector<int> &seq,int n) {
  int max_sum = seq[0];
  for(int i=0;i<n;i++) {
    int cur = 0;
    for(int j=i;j<n;j++) {
      cur += seq[j];
      max_sum = max(max_sum,cur);
    }
  }
  return max_sum;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  while(cin >> n) {
    if(n == 0) break;
    vector<int> seq(n);
    for(int i=0;i<n;i++) {
      cin >> seq[i];
    }
    cout << maximum_sum_seq(seq,n) << endl;
  }
}

C++: #include <stdio.h>

int main(void)
{
	long num[10000], sum, max;
	int n, i, j, k;
	
	while (scanf("%d", &n), n != 0){
		sum = 0;
		max = 0;
		for (i = 0; i < n; i++)scanf("%ld", &num[i]);
		for (i = 0; i < n - 1; i++){
			sum = num[i];
			for (j = i + 1; j < n; j++){
				sum += num[j];
				if (max < sum)max = sum;
			}
		}
		
		printf("%ld\n", max);
	}
	
	return (0);
}

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

C++: #include <bits/stdc++.h>

using namespace std;

int s[5001];

int main()
{
    int n;

    while (cin >> n, n) {
        memset(s, 0, sizeof(s));

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

        int ma = -1000000;

        for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
            ma = max(ma, s[i] - s[j - 1]);
        }

        cout << ma << endl;
    }
}

C++: #include <iostream>
#define INF 1e+9
using namespace std;

int main(){
	int n;
	while(cin >> n,n){
		int a,dp[5001] = {},ma = -INF;
		for(int i = 0;i <= n;i++) dp[i] = -INF;
		for(int i = 0;i < n;i++) {
			cin >> a;
			dp[i + 1] = max(a,dp[i] + a);
			ma = max(ma,dp[i + 1]);
		}
		cout << ma << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){

	int A[100000]={};
	int n,MAX = -100000;

		while(1){
			MAX = -100000;

			cin >> n;

			if( n == 0 ) break;

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

				cin >> A[i];
	
			}

			for(int i = 1; i <= n; i++){

				A[i] = max(A[i],A[i] + A[i-1]);
				MAX = max(A[i], MAX);

			}
	
			cout  << MAX << endl;

		}
	return 0;
}

C++: #include <iostream>

#define SIZE 5001

using namespace std;

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

		int list[SIZE], max = -114514;
		list[0] = 0;
		for (int i = 0; i < n; i++) {
			cin >> list[i + 1];

			if (list[i + 1] > max) {
				max = list[i + 1];
			}
			list[i + 1] += list[i];
		}

		for (int i = 2; i < n; i++) {
			for (int j = i; j < n; j++) {
				if (list[j] - list[j - i] > max) {
					max = list[j] - list[j - i];
				}
			}
		}

		if (list[n] > max) {
			max = list[n];
		}
		cout << max << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(void) 
{
    int num[5000];
	int cut_i,max;
	int kousuu;
	int nyuryoku;

	while(1){
		scanf("%d",&kousuu);
		
		if(kousuu == 0){
			break;
		}

		int kou = 0;
		
		for(cut_i=0;cut_i<kousuu;cut_i++){
			num[cut_i]=0;
		}

		for(cut_i=0;cut_i<kousuu;cut_i++){
			scanf("%d",&nyuryoku);

			if(num[kou] * nyuryoku <0){
				kou++;
			}
			num[kou]+=nyuryoku;

			if(max<num[kou]){
				max = num[kou];
			}
		}

		kou++;
		cut_i = 0;
		
		for(cut_i=0;cut_i<kou;cut_i++){

			if(max<num[cut_i]){
				max = num[cut_i];
			}
			
			if(num[cut_i]+num[cut_i+1] > 0){
				num[cut_i+1]+=num[cut_i];
			}
		}

		printf("%d\n",max);

	}
    return 0;
}

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

int main(){
	const int MAX_n = 5000;
	int n, a[MAX_n + 1], z, beg, res;
	
	while(true){
		scanf("%d", &n);
		
		if(n == 0) return 0;
		
		a[0] = 0;
		for(int i = 1; i <= n; i++){
			scanf("%d", &z);
			a[i] = z + a[i - 1];
		}
		
		beg = 0;
		res = 0;
		for(int i = 1; i <= n; i++){
			beg = min(beg, a[i - 1]);
			res = max(res, a[i] - beg);
		}
		
		printf("%d\n", res);
	}
}

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

int main() {
	int a[5000];
	int n;
	int sum = 0;
	int m = 0;
	while(1){
		scanf("%d", &n);
		m = 0;
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		
		for(int i = 0; i < n; i++){
			sum = 0;
			for(int j = i; j < n; j++){
				sum += a[j];
				m = max(sum, m);
			}
		}
		cout << m << endl;
	}
	return 0;
}