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 <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  while(cin>>n,n){
    vector<int> a(n+1);
    LOOP(i,1,n+1)cin>>a[i];
    LOOP(i,1,n+1)a[i+1]+=a[i];
    int ans=-INF;
    LOOP(i,1,n+1){
      LOOP(j,0,i){
        ans=max(ans,a[i]-a[j]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	while(n != 0){
		int a[n];
		

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

		int maximum = -100000000;
		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;
		cin >> n;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[5000];
	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++){
		for(int first=0;first+lon<=n;first++){
			int count=0;
			for(int k=0;k<lon;k++)
				count+=a[first+k];
			if(count>best)
				best=count;
		}
	}
	cout<<best<<endl;
	}
	return 0;
}

C++: /*AOJ 0022*/

#include<iostream>
#include<vector>
using namespace std;

int main(){

	int n;

	vector<int> ansMax;

	for(;;){

		cin>>n;

		if(n==0){
			break;
		}

		vector<int> data;
		int max=0;
		int sum=0;

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

			int tmp;
			cin>>tmp;

			data.push_back(tmp);

		}

		for(int i=0;i<n;i++){
			sum = 0;
			if(data.at(i)<0){
				continue;
			}
			for(int j=i;j<n;j++){
				sum+=data.at(j);
				if(sum>=max){
					max = sum;
				}
			}
		}
		data.clear();

		ansMax.push_back(max);

	}

	for(int i=0;i<ansMax.size();i++){
		cout<<ansMax.at(i)<<endl;
	}

	return 0;
}

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

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

int n;
int as[100000];

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;
  
    for (int i=0; i<n; i++) {
      scanf("%d", &as[i]);
    }
  
    int l = 0;
    int r = 0;
    int cur = 0;
    int ans = as[0];
    while (l < n) {
      while (r < n && cur >= 0) {
        cur += as[r++];
        ans = max(ans, cur);
      }
  
      l = r;
      cur = 0;
    }
  
    printf("%d\n", ans);
  }
}

C++: #include<iostream>
#include<cstring>
using namespace std;
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
    long int s[N];
    int n;
    while(cin >> n &&n)
    {
        if(n==0)break;
        memset(s,0,sizeof(int)*N);
        int t;
        long int max = 0;
        long int min = 0;
        for(int i=0;i<n;i++){
            cin >>t;
            s[i+1] = s[i]+t;
            if(max<s[i+1])max = s[i+1];
            if(min>s[i+1])min = s[i+1];
        }
        cout << max -min << endl;

    }

    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
	int n;
	int a[5010];
	for(;cin>>n,n;){
		int max=0;
		int m=0;
		bool f=false;
		for(int i=0;i<n;i++){
			cin>>a[i];
			if(a[i]>0)m+=a[i],max=max<m?m:max,f=true;
			else if(a[i]+m>0)m+=a[i];
			else m=0;
		}
		if(f)cout<<max<<endl;
		else{
			int mx=-10000000;
			rep(i,n)mx=mx<a[i]?a[i]:mx;
			cout<<mx<<endl;
		}
	}
	return 0;
}

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

int main(){
  int n, a;
  long long ing max_, tmp;
  while(cin >> n){
    max_=0; tmp=0; tmp=0;
    for(int i=0; i<n; i++){
      cin >> a;
      tmp = max(0,tmp+a);
      max_ = max(tmp,max_);
    }
    cout << max_ << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>

using namespace std;


long sumarray(long *array, int idx1, int idx2);


int main(){
  int n;
  long Max, ibuf;
  long *List;

  //ifstream ifs("input.txt"); // for debug

  cin >> n;
  while(1){

    // allocate and set value //////////////////////////////
    List = new long[n];
    for(int i=0; i<n; i++) cin >> List[i];

    // solve part //////////////////////////////////////////
    Max = 0;
    for(int l=1; l<=n; l++){
      ibuf = sumarray(List, 0, l);
      if(ibuf > Max) Max = ibuf;
      for(int i=0; i<n-l; i++){
	ibuf += List[i+l] - List[i];
	if(ibuf > Max) Max = ibuf;
      }
    }

    // deallocate //////////////////////////////////////////
    delete List;

    // output //////////////////////////////////////////////
    cout << Max;

    // for next loop //////////////////////////////////////
    cin >> n;
    if(n == 0) break;
    else cout << endl;

  }
  return 0;
}


long sumarray(long *array, int idx1, int idx2){ // array[idx1] + ... + array[idx2-1]
  long ret = 0;
  for(int i=idx1; i<idx2; i++){
    ret += array[i];
  }
  return ret;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
int n;
while(true){
cin>>n;
if(n==0)
break;
int best=0;
for(int i=0;i<n;i++)
 cin>>a[i];
 
for(int start=0;start<n;start++){
 int 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(){
   int count,max;
   int sum,data_set[5000];
  while(cin>>count){
    if(!count)break;
    cin>>data_set[0];
    max=data_set[0];
    for(int i=1;i<count;i++){
      cin>>data_set[i];
    }
     for(int i=1;i<=count;i++){
      for(int j=0;j<count;j++){
	for(int k=j;k<i;k++){
	  sum+=data_set[k];
	}
	if(max<sum)max=sum;
	sum=0;
      }
    }
    cout<<max<<endl;
  }
}

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

int main()
{
	int a,max_ret=0;
	while(1){
		cin>>a;
		if(a==0){
			break;
		}
		int n[5000];
		for(int i=0;i<a;i++){
			cin>>n[i];
		}
		int dp[5000];
		dp[0] = n[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_ret = max( dp[i], max_ret);
		}
		
		cout<<max_ret<<endl;
	}
	
	
	return 0;
}

C++: #include <iostream>
#include <vector>
int main(){
	int n;
	while(std::cin >> n, n){
		std::vector<int> v;
		for(int i=0;i<n;i++){
			int a;
			std::cin >> a;
			v.push_back(a);
		}

		int max = 0;
		for(int i=0;i<n;i++){
			int k = 0;
			for(int j=i;j<n;j++){
				k += v[j];
				if(k > max)max = k;
			}
		}

		std::cout << max << std::endl;
	}	
}