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<bits/stdc++.h>
#define ll long long
using namespace std;

ll ara[10000];
int main()
{
    ll n;
    while(scanf("%lld", &n))
    {
        if(n==0) break;
        for(ll i=1; i<=n; i++){
            scanf("%lld", &ara[i]);
        }

        ll p=0;
        ll s=0;
        for(ll i=1; i<=n; i++){
            s = max(ara[i], s+ara[i]);
            p = max(p, s);
        }
        printf("%lld\n", p);
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int a[5001], ans = -114514;
		for (int i = 0; i < n; i++)cin >> a[i];
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				int cnt = 0;
				for (int k = i; k <= j; k++) cnt += a[k];
				if (ans < cnt)ans = cnt;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

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

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; 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];
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

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;

}

C++: #include<stdio.h>

int main()
{
	int n;
	while(scanf("%d",&n))
	{
		if(n==0){return 0;}
		
		int a[5000]={0},max=0;
		for(int x=0;x<n;x++)
		{
			scanf("%d",&a[x]);

			for(int y=0;y<=x;y++)
			{
				if(y!=x)
				{
					a[y]+=a[x];
				}
				if(max<a[y])
				{
					max=a[y];
				}
			}
		}
		printf("%d\n",max);
	}
}

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

int main(){
	int n, max1, max2, a[5001];

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

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		vector<int> a;
		for(int i=0;i<n;i++){
			int b;
			cin>>b;
			a.push_back(b);
		}
		vector<int> sum;
		for(int j=0;j<a.size();j++){
			int s=0;
			for(int k=j;k<a.size();k++){
				s += a[k];
				sum.push_back(s);
			}
		}
		sort(sum.begin(),sum.end());
		cout<<sum[sum.size()-1]<<endl;
	}
	return 0;
}

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

void main() {
	int n;

	while (cin >> n) {
		if (n == 0) break;
		vector<int> array(n);
		for (int i = 0; i < n; i++) {
			cin >> array.at(i);
		}

		long max = array.at(0);
		for (int j = 0; j < n; j++) {
			long total = 0;
			for (int k = 0; k < n - j; k++) {
				total += array.at(j + k);
				if (total > max) max = total;
			}
		}

		cout << max << endl;
	}
	return;
}

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

int main(){
	int a[10000],n,s,m;
	while(cin>>n,n){
		m=INT_MIN;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=1;i<=n;i++){
			for(int j=0;j<n-i+1;j++){
				s=0;
				for(int k=0;k<i;k++){
					s+=a[j+k];
				}
				m=max(m,s);
			}
		}
		cout<<m<<endl;
	}
}

C++: #include<cstdio>
#define MAX(x,y) ((x>y)? x:y)

int n;
int a[5005];
long long int def;
long long int answer=-1000000000;

int main()
{
	while(true)
	{
		answer=-1000000000;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			def=0;
			for(int j=i;j<n;j++)
			{
				def+=a[j];
				answer=MAX(answer,def);
			}
		}
		printf("%lld\n",answer);
	}
	return 0;
}

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

using namespace std;


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


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

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

  cin >> n;
  while(1){

    // allocate and set value //////////////////////////////
    List = new int[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;
}


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

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000
using namespace std;
int main() {
	int n;
	while (cin >> n,n) {
		int ans = -INF, cnt = 0;
		rep(i, n) {
			int a;
			cin >> a;
			if (cnt < 0) cnt = a;
			else cnt += a;
			ans = max(ans, cnt);
		}
		cout << ans << endl;
	}
	return 0;
}