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>

using namespace std;

int main()
{
    while(1)
    {
        int n;
        cin>>n;if(!n)return 0;
        long long a[5010];
        for(int i=0;i<n;++i){
            cin>>a[i];
        }
        long long ans;
        long long buf;
        for(int i=0;i<n;++i){
            buf=0;
            for(int j=i;j<n;++j){
                buf+=a[j];
                if(buf>ans)ans=buf;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int answer[500] = {0};
    int l = 0;
    while(cin >> number,number)
    {
        int a[5010] = {0};
        vector<int>tempmax(500.500);
        vector<int>tempmax2(1000);
        REP(i,number)
        cin >> a[i];
        for(int i = number;i>=0;i--)
            for(int j = 0; j<i;j++)
            {
                tempmax[i] +=a[j];
            }
        for(int k = 0;k<number;k++)
            for(int m = k;m<number;m++)
            {
                if(k == m)
                    tempmax2[k] = a[k];
                else if(tempmax2[k]+a[m] >= tempmax2[k])
                    tempmax2[k]+= a[m];
                else
                    break;
            }
        sort(tempmax.begin(),tempmax.end(),greater<int>());
        sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        if(tempmax[0]>tempmax2[0])
            answer[l] = tempmax[0];
        else
            answer[l] = tempmax2[0];
        l++;
    }
    REP(i,l)
    cout << answer[i] << endl;
}

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

#include<vector>

#define INF 999999
using namespace std;
int main(){
    int N;
    while(cin>>N,N){
        int num[5500]={0},max=-INF;
        for(int i=0;i<N;i++){
            cin>>num[i];
        }
        for(int i=0;i<N;i++){
            int total=0;
            if(max<num[i])max=num[i];
            total+=num[i];
            for(int j=i+1;j<N;j++){
                total+=num[j];
                if(max<total)max=total;
            }
        }
        cout<<max<<endl;
    }
    return 0;
}

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

using namespace std;

int debug = 0;

int main(void){
	int n, m, i, j, k;
	int tmp, max;
	vector<int> intv;

	while(cin >> n){
		if(n == 0){
			break;
		}else{
			//ÇÝÝ
			for(i=0;i<n;i++){
				cin >> m;
				intv.push_back(m);
				if(debug) cout << "int[" << i << "] =" << intv[i] << endl; 
			}
			max = 0;
			int vsize = intv.size();
			for(i=1;i<=vsize;i++){//i:Â
				if(debug) cout << "number =" << i << endl;
				for(j=0;j<=vsize-1-i+1;j++){ //j:JnÊu
					tmp = 0;
					for(k=0;k<i;k++){
						tmp += intv[j+k];
					}
					if(debug) cout << "tmp ==" << tmp << endl;
					if(max <= tmp){
						max = tmp;
					}
				}
			}
			cout << max << endl;
			intv.clear();
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include<math.h>
using namespace std;

int main(){
	int n,maximum,sum;
	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		int array[n];
		for(int i=0;i<n;i++)scanf("%d",&array[i]);
		maximum = -600000000;
		for(int k=0;k<n;k++){//?§????????????????
			for(int j=k;j<n;j++){ //??????????????????
				sum = 0;
				for(int p=k;p<=j;p++){	//??????????????????
					sum += array[p];
				}
				maximum = (maximum >= sum)? maximum:sum;
			}
		}
		printf("%d\n",maximum);
	}

    return 0;
}

C++: #include<iostream>
using namespace std;
bool same(int a,int b){
  if(a*b>=0) return true;
  return false;
}
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int d;
    int s[n];
    int count = 0,begin = 0;
    int ans = -100000000;
    for(int i=0;i<n;i++){
      cin >> d;
      if(i==0) s[0] = d;
      else if(same(d,s[count])) s[count] += d;
      //cout << same(d,s[count]) << endl;
      else{
	count++;
	s[count] = d;
      }     
    }
    //for(int i=0;i<=count;i++) cout << s[i] << endl;
    if(s[0]<0) begin = 1;
    for(int i=begin;i<=count;i+=2){
      int h = s[i];
      if(ans<h) ans = h;
      for(int j=i+1;j<=count;j++){
	h += s[j];
	if(ans<h) ans = h;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int a[5001];
int main(){
    int n;
    while(cin >> n && n){
        rep(i, n) cin >> a[i];
        int ans = -INF;
        REP(i, 0, n){
            int sum = a[i];
            REP(j, i + 1, n){
                sum += a[j];
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<int> a(n);
		for(int i=0; i<n; i++){
			cin >> a[i];
		}
		
		int ans=-inf;
		for(int i=0; i<n; i++){
			int sum=0;
			for(int j=0; i+j<n; j++){
				sum += a[i+j];
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int64_t a[5000];
int64_t dp[2][5000];

int64_t solve(int n){
  int64_t summax=INT64_MIN;
  for(int i=0;i<n;i++){
    if(summax < a[i]){
      summax = a[i];
    }
  }

  for(int i=1;i<n;i++){
    for(int j=0;j<n-i;j++){
      dp[i%2][j] = dp[(i-1)%2][j] + a[i+j];

      if(summax < dp[i%2][j]){
        summax = dp[i%2][j];
      }
    }
  }
  return summax;
}

int main(){
  int64_t n;
  while(cin >> n,n!=0){

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

    cout << solve(n) << endl;
  }
  return 0;
}

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

int main(void){
  int n, input;
  long sum, max;
  while(cin >> n, n != 0){
    cin >> input;
    max = sum = input;
    for(int i = 0; i < n - 1; i++){
      cin >> input;
      if( sum < 0 )
	sum = input;
      else
	sum += input;
      if( max < sum )
	max = sum;
    }
    cout << max << endl;
  }
  return 0;
}