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<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
        vi v(n+1,0);
        rep(i,n)cin>>v[i];
        ll ans=-INF, temp;
        for(int i=0;i<n;i++){
            temp=0;
            for(int j=i;j<n;j++){
                temp+=v[j];
                ans=max(ans,temp);
            }
        }
        if(n==1)cout<<v[0]<<endl;
        else cout<<ans<<endl;
    }
}

C++: #include <stdio.h>

int seqsum(int n){
	int a = 0;
	int b[5000];
	int c = 0;
	int s = 0;
	scanf("%d", &a);
	b[0] = s = a;

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

	int m = b[0] < 0 ? 0 : b[0];
	int sum = m;
	for(int i=1; i<=c; ++i){
		if(m < 0 && m < b[i]){
			sum = m = b[i];
		}else{
			sum += b[i];
			if(m < sum){
				m = sum;
			}
		}
	}
	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<cstdio>
#include<vector>

using namespace std;

int main(void){
	int n;
	while(scanf("%d", &n) && n){
		
		int num[5001]={0};
		int total[5001]={0};
		int ans = -2000000000;
		
		for(int i = 0; i < n; i++){
			scanf("%d", &num[i]);
		}
		
		for(int i = 0; i < n; i++){
			for(int j = i; j < n; j++){
				total[i] += num[j];
				ans = max(ans,total[i]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int n, a[5010], sum[5010], res;
  while (true) {
    cin >> n;
    if (n == 0) break;
    rep (i, n) cin >> a[i];
    sum[0] = 0;
    rep (i, n) sum[i + 1] = a[i] + sum[i];
    res = -1000000000;
    rep (i, n) rep (j, i + 1) {
      res = max(res, sum[i + 1] - sum[j]);
    }
    cout << res << endl;
  }
}

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

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

    int max = INT_MIN;
    int maxBfr = INT_MIN;
    int bfr = INT_MIN;
    int before = INT_MIN;

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

      if(maxBfr > 0) {
	maxBfr += bfr;
      } else {
	maxBfr = bfr;
      }

      int sum;
      sum = maxBfr+temp;

      if(maxBfr != INT_MIN && sum > max && sum > temp) {
	max = sum;
      } else if(temp > max) {
	max = temp;
      }

      bfr = temp;
    }

    cout << max << endl;
  }
  return 0;
}

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

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

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

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

int main(){
        int n, a[5010];
        while(cin >> n && n){
                for(int i=0; i<n; i++){
                        cin >> a[i];
                }
                long max = 0;
                for(int i=0; i<n-1; i++){
                        for(int j=i+1; j<n; j++){
                                long sum = 0;
                                for(int k=i; k<=j; k++){
                                        sum += a[k];
                                }
                                max = (max > sum)? max:sum;
                        }
                }
                cout << max << endl;
        }
}

C++: #include<stdio.h>
#include<stdlib.h>
#include <math.h>
#include<string.h>
#include<limits.h>

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

C++: #include<iostream>
using namespace std;
int main(){
  int n,i,j;
  cin >> n;
  while(n!=0) {
    long long sum[5001]={};
    int b;
    long long o=1<<10;
    o*=-1;
    cin >> sum[1];
    for(i=2;i<=n;i++){
      cin >> b;
      sum[i]=sum[i-1]+b;
      //cout << sum[i] << endl;
    }
    
    for(i=0;i<=n;i++){
      for(j=i+1;j<=n;j++){
	o=max(o,sum[j]-sum[i]);
      }
    }
    cout << o << endl;
    cin >> n;
  }
  return 0;
  
}

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

using namespace std;

int main() {
  int n;
  vector<int> datas;
  vector<int> sums;

  while (cin >> n, n != 0) {
    int input;
    for (int n_i = 0; n_i < n; n_i++) {
      cin >> input;
      datas.push_back(input);
    }
    for (int data_i = 0; data_i < n-1; data_i++) {
      sums.push_back(datas[data_i]+datas[data_i+1]);
    }

    int max = *sums.begin();
    for (vector<int>::iterator sum_i = sums.begin(); sum_i != sums.end(); sum_i++)
      if (max < *sum_i)
        max = *sum_i;
    cout << max << endl;
  }

  return 0;
}

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

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

C++: #include<iostream>
#include<string>
using namespace std;
int a[5000];
int main(){
int n;
while(true){
cin>>n;
if(n==0)
break;
long long best=0;
for(int i=0;i<n;i++)
 cin>>a[i];
 
for(int start=0;start<n;start++){
 long long count=0;
 for(int len=start;len<n;len++){
  count+=a[len];
  best=max(best,count);
 }
}

cout<<best<<endl;
}
return 0;   
}

C++: #include <iostream>
using namespace std;
int main(){
	for (;;){
		int a,goukei=0,max=0,b;
		cin>>a;
		if (a==0)break;
		int data[a+1]={0};
		for (int A=1;A<=a;A++){
			cin>>data[A];
			if (max<data[A])max=data[A];
			goukei+=data[A];
			data[A]=goukei;
			if (max<data[A])max=data[A];
		}
		for (int A=3;A<a;A++){
			b=A-2;
			for (int B=b;B>0;B--){
				goukei=0;
				goukei=data[A]-data[B];
				if (goukei>max) max=goukei;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

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

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

  while(1){
    priority_queue<ll> 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;
  }
}