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<vector>
#include<iostream>

using namespace std;

int main(){
	while(true) {
		long long int n, tmp;
	cin >> n;
	if (n<=0) {
		//cout << 0 << endl;
		return 0;
	}
	vector<long long int> intervalos;
	intervalos.reserve(n);
	cin >> tmp;
	bool esNegativo = tmp < 0;
	intervalos.push_back(tmp);
	for (int i = 1; i < n; ++i){
		cin >> tmp;
		if (esNegativo == tmp < 0){
			intervalos.back() += tmp;
		} else {
			intervalos.push_back(tmp);
			esNegativo ^= true;
		}
	}
	long long int best = 0;
	long long int current = 0;
	for (int i = 0; i < intervalos.size(); ++i){
		if (intervalos[i]+current <= 0) {
			current = 0;
		} else {
			current+=intervalos[i];
			if (current > best) {
				best=current;
			}
		}
	}
	intervalos.clear();
	cout << best << endl;
	}
	
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#define li long int
using namespace std;

int main()
{
  li n,a;
  li i,j;
  li b[5005]={};

  while(1){
    priority_queue<li> pq;
    cin>>n;
    if(n==0)break;
    for(i=1;i<=n;i++){
      cin>>a;
      b[i]=b[i-1]+a;
      for(j=i;j>=0;j--)
	pq.push(b[i]-b[j]);
    }
    cout<<pq.top()<<endl;
  }
}

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

using namespace std;

int main(){
	int n;
	int a[5000] = { 0 };

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

	return 0;

}

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

int main(){

  int n,count,maxu;

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

    int numbers[n];
    for(int i=0;i<n;i++)
      cin >> numbers[i];
    maxu = 0;

    for(int i=n-1;0<=i;i--){
      for(int j=0;i+j<n;j++){
	count = 0;
	for(int k=j;k<=j+i;k++)
	  count += numbers[k];
	maxu = max(maxu,count);
      }
    }
    cout << maxu << endl;

  }

  return 0;
}

C++: /**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0022&lang=jp
 */
#include <stdio.h>
#define N 5000

int getsign(int d){
	return d >= 0 ? 1 : -1;
}

int seqsum(int n){
	int a[N];
	int b[N];
	int c = 0;
	int s = 0;

	scanf("%d", a);
	b[0] = a[0];
	s = getsign(a[0]);

	for(int i=1; i<n; ++i){
		scanf("%d", a+i);
		if(s == getsign(a[i])){
			b[c] += a[i];
		}else{
			b[++c] = a[i];
			s = getsign(a[i]);
		}
	}

	int m = b[0];
	int sum = m;
	if(c == 0){
		if(m >= 0){ return m; }
		m = a[0];
		for(int i=1; i<n; ++i){
			if(m < a[i]){
				m = a[i];
			}
		}
		return m;
	}

	a[0] = b[0];
	m = a[0];
	for(int i=1; i<=c; ++i){
		a[i] = a[i-1] < 0 ? b[i] : a[i-1] + b[i];
		if(m < a[i]){
			m = a[i];
		}
	}

	//for(int i=1; i<=c; ++i){
	//	if(m < sum + b[i]){
	//		sum += b[i];
	//		m = sum;
	//	}else if(m < b[i]){
	//		sum = m = b[i];
	//	}else{
	//		sum += b[i];
	//	}
	//}

	return m;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    int n=0,a[5000]={0},saidai=-100000;
    while(cin>>n&&n!=0){
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;n>i;i++){
            int kazu=0;
            for(int x=i;x<n;x++){
                kazu=kazu+a[x];
                cout<<kazu<<endl;
                if(kazu>saidai){
                    saidai=kazu;
                }
            }
        }
        cout<<saidai<<endl;
    }
}

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

using namespace std;
typedef long long lint;

int main()
{
	int N;
	
	while (scanf("%d", &N) && N){
		lint maxi = -0x3fffffffffffffll;
		lint dist = maxi;
		for (int i = 0; i < N; i++){
			lint x;
			scanf("%lld", &x);
			dist = max(dist + x, x);
			maxi = max(maxi, dist);
		}
		printf("%lld\n", maxi);
	}
	
	return (0);
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int d[5005];
int main(void){
  while(1){
    int n;
    scanf("%d",&n);
    if(!n) break;
    for(int i=0;i<n;i++){
      scanf("%d",&d[i]);
      if(i) d[i]+=d[i-1];
    }
    int sum=d[0];
    for(int i=0;i<n;i++){
      sum=max(d[i],sum);
      for(int j=0;j<i;j++){
	sum=max(d[i]-d[j],sum);
      }
    }
    printf("%d\n",sum);
  }
}

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

int main(void){

	int a[5001];
	for(int i=0; i<5001; i++) a[i] = 0;

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

		int ans = -999999;
		int sum = 0;

		for(int i=0; i<n; i++){
			for(int j=0; j<(n-i); j++){
				sum = sum + a[i+j];
				if(sum>ans) ans=sum;
			}
			sum = 0;
		}

		cout << ans << endl;

		for(int i=0; i<5001; i++) a[i] = 0;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000],saidai=-100000;
	while(cin>>n&&n!=0){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;n>i;i++){
			for(int x=n;x>=i+1;x--){
				int kazu=0;
				for(int y=x;y>=i;y--){
					kazu=kazu+a[y];
				}
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}

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

int main(){
	int n;
	while(cin >> n && n){
		n++;
		vector<int> t(n), v(n);
		t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}
		cout << *max_element(t.begin(), t.end()) << endl;
	}
	return 0; 
}

/*
7
-5
-1
6
4
9
-6
-7
*/

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

int main()
{
	int n=1, count = 0;
	int a[10000];
	while (cin >> n) {
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = -100000;
		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)
			break;
		cout << max << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int a[5000],n;
signed main(){
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>a[i];
        int ma=LLONG_MIN;
        for(int i=0;i<n;i++){
            int cur=0;
            for(int j=i;j<n;j++){
                cur+=a[j];
                ma=max(ma,cur);
            }
        }
        cout<<ma<<endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;


int main(void){

int nm=9;
int sum,j;
int su[5001]={0};

	while(1){
		cin >> nm;
		if(nm == 0) break;
		int mx = -999999999;
		rep(i,nm) cin >> su[i];
		rep(i,nm){
			sum=0;
			rep2(j,i,nm){
		 		sum += su[j];
				mx = max(mx,sum);
			}
		}
		cout << mx << endl;
	}
	return 0;
}

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

int main(){
  int n;
  int list[5000];

  while(cin>>n){
    if(n==0){
      break;
    }
    int temp=0;
    int max=0;
    for(int i=0; i<n; i++){
      cin >> list[i];
    }

    for(int i=0; i<n; i++){
      temp += list[i];
      if( temp<=0 ){
        temp=0;
      }
      if(max<temp){
        max=temp;
      }
    }

    cout << max << endl;
  }

  return 0;
}