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++: #include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n,x[5000];
  while(1){

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

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

  int now=0;
  int Max=-100001,tmp;
  for(int i = 0;i < n; i++){
    now+=x[i];
    tmp=now;

    for(int j=0;j < i;j++){
      Max=max(Max,now);
      now-=x[j];
      }

    now=tmp;
    }
  cout << Max << endl;
} 

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define in        []{int n; cin>>n; return n;}()

int main() {
    int N = in;
    if( !N ) return 0;
    vector<int> A(N+1, 0);
    rep( i, N ) A[i+1] = in + A[i];
    int ans = INT_MIN;
    rep( r, N+1 ) rep( l, r ) ans = max( ans, A[r] - A[l] );
    cout << ans << "\n";
    main();
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;

int main(void){
    for(int n, res, sum; cin >> n, n; cout << res << endl){
        res = sum = 0;
        while(n --){
            int a; cin >> a;

            sum += a;
            if(sum < 0){
                sum = 0;
                if(res < a) res = a;
            }
            else
                if(res < sum) res = sum;
        }
    }

    return 0;
}

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

using namespace std;

int main(){

  int n;


  while(cin >> n){
    if(n == 0) break;
    vector<int> V;
    int status = 1;
    int in;
    int sum = 0;
    for(int i = 0; i < n; i++){
      cin >> in;
      if(i == 0){
	if(in < 0) status = -1;
	else if(in > 0)status = 1;
	else V.push_back(0);


      } else {
	if(in == 0) V.push_back(0);

	if(in < 0 && status == 1){
	  status = -1;
	  V.push_back(sum);
	  sum = 0;
	}else if(in > 0 && status == -1){
	  status = 1;
	  V.push_back(sum);
	  sum = 0;
	}
      }
      sum += in;
    }

    V.push_back(sum);

    int max = -700000000;
    
    for(int i = 0; i < V.size(); i++){
      sum = 0;
      for(int j = i; j < V.size(); j++){
	sum += V[j];
	if(max < sum) max = sum;
      }
    }
    
    cout << max << endl;
  }
  return 0;
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int* a = new int[n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        long long max = a[0];
        for (int i = 0; i < n; i++) {
            long long sum = 0;
            for (int j = i; j < n; j++) {
                sum += a[j];
                if (max < sum) {
                    max = sum;
                }
            }
        }
        cout << max << endl;
        delete[] a;
    }
}

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

bool state = false ;

int main()
{
	int n ;
	while(1)
	{
		cin >> n ;
		if( ! n ) return 0 ;
		
		int * p = new int [n] ;
		
		for(int i = 0 ; i < n ; i ++)
		{
			cin >> p[i] ;
		}
		
		int max , pos_b , pos_e , contain ;
		max = pos_b = pos_e = contain = 0 ;
		
		for(int i = 0 ; i < n ; i ++)
		{
			if(contain < 0) contain = 0 ;
			else 
			{
				contain += p[i] ;
			}
			
			if(contain > max) max = contain ;
		}
		
		if(state) cout << endl ;
		state = true ;
		cout << max ;
	} 
	return 0 ;
 }

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

int main()
{
    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) break;

        int a[5000];
        for (int i = 0; i < n; ++i) std::cin >> a[i];

        int max = std::numeric_limits<int>::min();
        for (int i = 0; i < n; ++i) {
            int sum = a[i];
            if (max < a[i]) max = a[i];
            for (int j = i + 1; j < n; ++j) {
                sum += a[j];
                if (max < sum) max = sum;
            }
        }
        std::cout << max << std::endl;
    }
}

C++: #include<stdio.h>
int main(){
	int a;
	while(1){
		scanf("%d",&a);
		if(a==0)return 0;
		long long int n[10000];
		for(int i=0;i<a;i++)scanf("%lld",n+i);
		long long int dp[10000];
		dp[0]=n[0];
		long long 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];
			if(max<dp[i])max=dp[i];
		}
		printf("%lld\n",max);
	}
}

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

#define MAX 5000

using namespace std;

int main(void){

	int n,a[5000];
	int wa,max;

	while(1){
		cin>>n;
		wa=0;
		for(int i=0;i<n;i++) cin>>a[i];
		max=a[0];
		for(int i=n-1;i>=0;i--){
			wa+=a[i];
			if(wa<0) wa=0;
			if(wa>max) max=wa;
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int arr[5000];

int p14(int size) {
	int i=0;
	int j=0;
	int sum = arr[0];
	int smax = arr[0];
	
	int s = 0;
	
	for (int t=1; t<size; t++) {
		sum+=arr[t];
		
		if ( sum > smax ) {
			i = s;
			j = t;
			smax = sum;
		}
		
		if (sum < 0 ) {
			for(; s<=t; s++) {
				sum -= arr[s];
				if ( sum > smax ) {
					i = s;
					j = t;
					smax = sum;
				}
			}
		}
	}
	
	return smax;
}

int main(void) {
	while(true) {
		int n;
		scanf("%d", &n);
		if ( n==0 ) { return 0; }
		
		for(int i=0; i<n; i++) {
			scanf("%d", &arr[i]);
		}
		
		printf("%d\n", p14(n));
	}
}

C++: // start 20:09
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

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

using namespace std;

int sum(vector<int> &nums, int oft, int len) {
    int ret = 0;
    for ( int i = 0; i < len; i++ ) {
        ret += nums[oft+i];
    }
    return ret;
}

int main() {
    int n;
    
    while(cin >> n, n) {
        int max_n;
        vector<int> nums(n);

        REP(i, n) cin >> nums[i];

        cout << nums[0] << " " << nums[1] << " " << nums[2] << endl;        
        max_n = nums[0];

        cout << "m:" << max_n << endl;

        REP(oft, n) for( int len = 1; len <= n-oft; len++ ) {
            // cout << oft << " " << len << endl;
            max_n = max(max_n, sum(nums, oft, len));
            cout << max_n << " " << oft << " " << len << endl;
        }
        cout << max_n << endl;
    }

    return 0;
}

C++: #include<stdio.h>
int ar[5000];
int d[5000];

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){
	int n,i,j;
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		for(i=0;i<n;i++){
			scanf("%d",&ar[i]);
		}
		d[0]=0;
		int ans=0;
		for(i=1;i<n+1;i++)d[i]=d[i-1]+ar[i-1];
		for(i=0;i<n;i++)for(j=i+1;j<n+1;j++){
			ans=max(ans,d[j]-d[i]);
		}
		printf("%d\n",ans);
	}
}