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 <limits.h>
using namespace std;

int main() {
  int n;
  int a[5000];
  int sum[5001];
  int tmp;
  int max;
  while (cin >> n, n) {
    for (int i=0; i<n; i++) {
      cin >> a[i];
    }
    sum[0] = 0;
    for (int i=0; i<n; i++) {
      sum[i+1] = sum[i] + a[i];
    }

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

  return 0;
}

C++: #include <stdio.h>

#define SGN(X) ((X)>0?1:(X)<0?-1:0)
int compressRead(int a[], int n);

int main(void){
	int n;
	int a[5000];
	int max, cur;
	
	while (scanf("%d", &n), n){
		n = compressRead(a, n);
/*		printf("a[%d]:", n);
		for (int i=0; i<n; i++){
			printf("%d ", a[i]);
		}
		puts(""); */
		max = a[0];
		for (int i=0; i<n; i++){
			cur = 0;
			for (int j=i; j<n; j++){
				cur += a[j];
				if (cur > max) max = cur;
			}
		}
		printf("%d\n", max);
	}
	
	return 0;
}

int compressRead(int a[], int n){
	int idx=0;
	int x,last;
	
	scanf("%d", &x);
	last=a[idx]=x;
	for (int i=1; i<n; i++){
		scanf("%d", &x);
		if (x==0) continue;
		if (x<0){
			a[++idx] = x;
//			printf("a[%d] = \%d\n",idx,x);
		}else{
			if (last<0) a[++idx]=0;
			a[idx]+=x;
//			printf("a[%d] += %d (=%d)\n", idx, x, a[idx]);
		}
		last = x;
	}
	
	return idx+1;
}

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

	int n, max=0;
	int *a;
	int sum;

	do{
		max = 0;
		//cout << endl;
		cin >> n;

		if (n == 0) break;

		a = new int[n];

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

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

			sum = 0;

			cin >> a[i];

			for (int j = i; j >= 0; j--){

				sum += a[j];
				if (max < sum) max = sum;
			}
		}

		cout << max << endl;
	} while (1);
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0)
			break;
		int a[n];
		for(int i=0; i<n; i++)
			cin>>a[i];
		int maximum=-100000;
		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;
	}
	return 0;
}

C++: #include <stdio.h>

int main()
{
	int n, x, p;
	
	while(scanf("%d", &n) != 0){
		if (n == 0) break;
		
		int a[n];

		for(int i = 0; i < n; i++){
			scanf("%d", &a[i]);
		}

		x = a[0];

		for(int i = 1; i <= n; i++){
			for(int j = 0; j < n-i+1; j++){
				p = 0;

				for(int k = 0; k < i; k++){
					p += a[j+k];
				}

				if(x < p) x = p;
			}
		}

		printf("%d\n", x);
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[5001];
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int best=0;
	for(int lon=1;lon<=n;lon++){
		int g=0;
		for(int i=0;i<lon;i++)
			g+=a[i];
		if(g>best)
			best=g;
		for(int first=1;first+lon<=n+1;first++){
			g+=a[first+lon-1]-a[first-1];
			if(g>best)
				best=g;
		}
	}
	cout<<best<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,math[5010],most,bell;
  while(1){
    cin >> n;
    if(n==0){
      break;
    }

    most=0;

    for(int i=0;i<n;i++){
      cin >> math[i];
    }
    for(int i=0;i<n;i++){
      bell=math[i];
      for(int j=i+1;j<n;j++){
	bell+=math[j];
	if(most<bell){
	  most=bell;
	}
      }
    }
    cout << most << endl;
  }
}

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

int main() {
	int n, a, zip = 0;
	vector<int> an;
	vector<vector<int>> AN;
	while (cin >> n) {
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> a;
			if (a >= 0)zip += a;
			else {
				if(zip==0)an.push_back(a);
				else {
					an.push_back(zip);
					an.push_back(a);
					zip = 0;
				}
			}
		}
		AN.push_back(an); an.clear();
	}

	for (int i = 0; i < AN.size(); i++) {
		int max = 0, MAX = 0 , counter = 0;
		for (int j = 0; j < AN[i].size(); j++) {
			if (AN[i][j] >= 0) {
				max += AN[i][j];
				if (MAX < max)MAX = max;
				counter = 1;
			}
			else {
				if (counter==1){
					if (AN[i][j] + max >= 0)max += AN[i][j];
					else {
						if (MAX < max)MAX = max;
						max = 0;
						counter = 0;
					}
				}
			}
		}
		cout << MAX << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
using namespace std;

int gcd(long long int m,long long int n){
	while(m!=n){
		if(m>n){m=m-n;
		}
		else n=n-m;
	}
	return m;
}
int lmc(long long int m,long long int n){
return m*n/gcd(m,n);
}

int main(){
int n;
while(cin>>n,n!=0){
	int a[5000];
	long int sum[5000]={0};
	long int prev=-10000;
	int num;
	for (int i=0;i<n;i++){
		cin>>a[i];
		if(i==0){
			sum[i]=a[i];
		}
		else
		{sum[i]=sum[i-1]+a[i];}
		if(sum[i]>prev){
			prev=sum[i];
			num=i;
		}
	}
	int ans[5000]={0};
	ans[0]=prev;
	for (int i=0;i<num;i++){
		ans[i+1]=prev-sum[i];
	}
	sort(ans,ans+5000);
	cout<<ans[4999]<<endl;
}

}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 

int main(void){  
  int n;
  while(cin>>n,n){
    int maxs = 0;
    int a[10001] = {0};
    REP(i,n) cin >> a[i];
    FOR(i,0,n){
      int sum =0;
      FOR(j,i,n){
        sum += a[j];
        maxs = max(sum, maxs);
      }
    }
    cout << maxs << endl;
  }
  return 0;
}

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

int main() {
	int n;
	while (true) {
		cin >> n;
		if (n == 0)break;
		int* nums = new int[n];
		for (int i = 0; i < n; i++) {
			cin >> nums[i];
		}
		int max = 0; 
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n - i; j++) {
				int tmp = 0;
				for (int k = i; k <= j; k++) {
					tmp += nums[k];
				}
				if (max < tmp)max = tmp;
			}
		}
		cout << max << endl;
	}
}