Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var infty = 100000 * 2
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	scanner.Scan()
	return strconv.Atoi(scanner.Text())
}

func findMaximumSubarray(arr []int) int {
	currentMaxSum, maxSumContainsTail := -infty, -infty

	for j := range arr {
		if arr[j] > maxSumContainsTail+arr[j] {
			maxSumContainsTail = arr[j]
		} else {
			maxSumContainsTail += arr[j]
		}
		if currentMaxSum < maxSumContainsTail {
			currentMaxSum = maxSumContainsTail
		}

		// fmt.Println(arr[j], currentMaxSum, maxSumContainsTail)
	}
	return currentMaxSum
}

func main() {
	scanner.Split(bufio.ScanWords)
	for {
		size, _ := nextInt()
		if size == 0 {
			break
		}

		arr := make([]int, size)
		for i := range arr {
			n, _ := nextInt()
			arr[i] = n
		}

		maximumSum := findMaximumSubarray(arr)
		fmt.Println(maximumSum)
	}
}

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

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

int seqsum(int n){
	int a[5000];
	int b[5000];
	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){
			m = __max(m, a[i]);
		}
		return m;
	}
	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<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<stack>
#include<set>
#include<cmath>

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

#define EPS 1e-6

using namespace std;

int main(){

   int n,a;
   while(true){
   cin >> n;
   if(n==0) break;

   vector<int>v;
   int s=0;
   v.push_back(s);

   rep(i,n){
   cin >> a;
   s+=a;
   v.push_back(s);
   }

   int vmin=0; int vmax=0;
   rep(i,n+1){
   if(v[i]<vmin) vmin=v[i];
   if(v[i]>vmax) vmax=v[i];

   }

	cout << vmax-vmin << endl;

   }

	return 0;
}

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

using namespace std;

int main(void){
	int Max, Num = 0, In;
	while (true){
		vector<int>	Dat;
		Max = -100000;
		cin >> Num;
		if (Num == 0)break;
		for (int i = 0; i < Num; i++){
			cin >> In;
			Dat.push_back(In);
		}
		for (int i = 1; i < Num; i++){
			Dat[i] = max(Dat[i], Dat[i - 1] + Dat[i]);
			Max = max(Max, Dat[i]);
		}
		cout << Max << endl;
	}
	return 0;
}

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

using namespace std;

int main(void){
	
	int n,j,sum,max1;
		
	while(cin>>n,n){
		
		vector<int> v;
		
		for(int i=0;i<n;i++){
			cin>>j;
			v.push_back(j);
		}
		max1=v[0];

		for(int i=0;i<n;i++){
				sum=0;
			for(int j=i;j<n;j++){
				sum=sum+v[j];
				max1=max(max1,sum);
			}
		}
		cout<<max1<<endl;
		

	}
}

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

int main()
{

	int n, num;
	vector< int > a;
	vector< int > res;

	while( 1 ) {

		int Max = -100000;

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

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		//?????§???
		for( int i = 1; i < n; i++ ) {
		
			a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

			if ( a[i] > Max ) {
				Max = a[i];
			}
		
		}

		res.push_back( Max );
		a.clear();
	
	}

	for( vector< int > :: iterator mIt = res.begin(); mIt != res.end(); ++mIt ) {
		cout << *mIt << endl;
	}

	return 0;

}

C++: #include <bits/stdc++.h>

using namespace std;

long maxSubArray(long arr[], int n)
{
	long maximum = arr[0];
	long currentMaximum = arr[0];
	long sum;
	for(int i = 1; i < n; i++) {
		sum = currentMaximum + arr[i];
		currentMaximum = max(arr[i], sum);
		maximum = max(maximum, currentMaximum);
	}
	return maximum;
}




int main()
{
	//freopen("input.txt", "r", stdin);
	long n;
	while(scanf("%ld", &n) == 1 && n != 0) {
		long arr[200001];
		for(int i = 0; i < n; i++) {
			cin >> arr[i];
		}

		cout << maxSubArray(arr, n) << endl;
	}

	return 0;
}

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

int main(){
	int n;
	
	while(cin>>n,n){
		int max=0;
		int sum[n];
		for(int i=0;i<n;i++){
			int num;
			cin>>num;			
			sum[i]=num;
			for(int j=0;j<i;j++){sum[j]+=num;if(max<sum[j])max=sum[j];}
		}
		cout<<max<<endl;
	}
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int A[5010];
int n;
int main()
{
  while(scanf("%d",&n)){
    if(n ==0)
      break;
  for(int i = 0;i < n;i++){
    cin>>A[i];
  }
  int ans = -(1<<25);
  for(int i = 0;i < n;i++){
    int sum = 0;
    for(int j = i;j <n;j++){
      sum +=A[j];
      ans =max(sum,ans);
    }
  }
  cout <<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int num;
    int input[5001];

    while (cin >> num) {
        if (!num)
            break;

        for (int i = 0; i < num; i++)
            cin >> input[i];

        int sum_max = input[0];
        for (int i = 0; i < num; i++) {
            int tmp = 0;
            for (int j = i; j < num; j++) {
                tmp += input[j];
                
                sum_max = max(tmp, sum_max);
            }
        }
        cout << sum_max << endl;
    }

    return 0;
}

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

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

C++: #include<bits/stdc++.h>
using namespace std;
int num[5000];
int  serch(int line,int now,int maxe)
{
    if(maxe==now)return line;
    return max(line,serch(line+num[now],now+1,maxe));
}
int main()
{
    int n;
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>num[i];
        int ans=num[0];
        for(int i=0;i<n;i++)ans=max(serch(num[i],i+1,n),ans);
        cout<<ans<<endl;
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<int>in(n);
    rep(i,n)cin>>in[i];
    int max=in[0];
    rep(i,n){
      int sum=0;
      loop(j,i,n){
	sum+=in[j];
	if(max<sum)max=sum;
      }
    }
    cout<<max<<endl;
  }


}