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<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    for(;;){
        long long int n,a[5001]={},ma=0,sum=0;
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        ma=-1e9;
        for(int i=0;i<n;i++){
            sum=0;
            for(int j=i;j<n;j++){
                sum+=a[j];
                ma=max(ma,sum);
            }
        }
        cout<<ma<<endl;
    }
return 0;
}

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

using namespace std;

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

  return 0;
}

C++: /*??£?¨?*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int main()
{
	int max = 0, n, a[5001] = {0},max_=0;
	while (cin >> n, n != 0)
	{
		max_ = 0;
		max = -1000000000;
		rep(i, n)
			cin >> a[i];
		rep(i, n)
		{
			for (int j = i; j < n; j++)
			{
				max_ += a[j];
				if (max < max_)
					max = max_;
			}
			max_ = 0;
		}
		cout << max << endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    while (1)
    {
        int n;
        cin >> n;
        if (n == 0)
            break;
        int a[n];
        rep(i, n) cin >> a[i];
        int m = a[0], sum = a[0];
        for (int i = 1; i < n; i++)
        {
            sum = max(sum + a[i], a[i]);
            if (sum > m)
                m = sum;
        }

        OP(m)
    }

    return 0;
}

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

int main(){
    int n;
    while(cin >> n, n){
        vector<int> a(n,0);
        for(int i=0; i<n; ++i){
            cin >> a[i];
        }
        // ????????£?¶??????????????????§??£?¶???????dp??¨?????????
        vector<int> dp(n,0);
        dp[0] = a[0];
        int max = 0;
        for(int i=1; i<n; ++i){
            if(dp[i-1]>0){
                dp[i] = dp[i-1] + a[i];
            } else {
                dp[i] = a[i];
            }
            if(max<dp[i]){
                max = dp[i];
            }
        }
        cout << max << endl;
    }
}

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

	int A[100000]={};
	int n,MAX = -100000;

		while(1){
			MAX = -100000;

			cin >> n;

			if( n == 0 ) break;

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

				cin >> A[i];
	
			}

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

				A[i] = max(A[i],A[i] + A[i-1]);
				MAX = max(A[i], MAX);

			}
	
			cout  << MAX << endl;

		}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

main(){
	while(true){
		int n;
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		int a[n];
		for(int i=0; i<n; ++i){
			cin >> a[i];
		}
		
		long long maxv = a[0];
		for(int l=0; l<n; ++l){
			long long sumv = 0;
			for(int r=l; r<n; ++r){
				sumv += a[r];
				if(sumv >= maxv){
					maxv = sumv;
				}
			}
		}
		
		cout << maxv << endl;
	}
}

C++: #include <iostream>

using namespace std;

int main(){
    seq();
    return 0;
}

int seq(){
    int a;
    while(cin >> a,a){
        int b[a];
        for(int i = 0; i < a; i++){
            cin >> b[i];
        }
        cout << max() << endl;
    }
}

int max(){
    int max = -10000000;
    int sum = 0;
    for(int len = 1; len <= a ; len++){
        for(int i = 0; i < a-len; i++){
            for(int j = 0, sum = 0; j < len; j++){
                sum += b[i+j];
            }
            if (sum > max) max = sum;
        }
    }
    return max
}

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

int main()
{

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

	while( 1 ) {

		int Max = -1000001;

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

		a.push_back( 0 );

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

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

	return 0;

}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
void maxSum(int a[],int n);
int main(){
	int n;
	while(cin>>n,n){
		int sum=0,a[5001],ans=-999999999;
		for(int i=0;i<n;i++)
            cin>>a[i];
        for(int i=0;i<n;i++){
            sum=0;
            for(int j=i;j<n;j++){
                sum+=a[j];
                ans=max(sum,ans);
            }
        }
    cout << ans << endl;
	}
	return 0;
}

void maxSum(int a[],int n){
    int sum = 0;
    int ans = -1;
    for(int i=0;i<n;i++){
        sum=0;
        for(int j=i;j<n;j++){
            sum+=a[j];
            ans=max(sum,ans);
        }
    }
    cout << ans << endl;
}

C++: #include <iostream>
int main(){
	int x;
	while(std::cin >> x){
		std::cerr << x << '\n';
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n,b;
	vector<int>a;
	while (1){
		int max_v = 0;
		a.clear();
		cin >> n;
		if (n == 0)break;
		a.push_back(0);
		for (int i = 0; i < n; i++){
			cin >> b;
			a.push_back(b);
		}
		for (int i = 1; i <= n; i++){
			a[i] = max(a[i - 1] + a[i], a[i]);
			if (a[i]>max_v){
				max_v = a[i];
			}
		}
		cout << max_v << endl;
	}
}

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

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {

		int Max = -100000;

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

		a.push_back( 0 );

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

		for( int i = 1; i < n - 1; i++ ) {
		
			a.at( i - 1 ) + a.at( i ) > a.at( i ) ? a.at( i ) = a.at( i - 1 ) + a.at( i ) : a.at( i ) = a.at( i );

			if ( a.at( i ) > Max ) {
				Max = a.at( i );
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}