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>
using namespace std;

int main(){
  int n;
  int tmp;
  int all;
  while(1){
    cin >> n;
    if(n == 0) break;
    int num[n];
    for(int i=0;i<n;i++) cin >> num[i];
    tmp = num[0];
    for(int i=0;i<n;i++){
      all = 0;
      for(int j=i;j<n;j++){
	all += num[j];
	if(tmp < all) tmp = all;
      }
    }
    cout << tmp << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <algorithm>
#include <cctype>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);

int n,ans;
vi dp,num;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		ans=-1
		dp=vi(n);
		num=vi(n);
		for(int i=0;i<n;i++) cin>>num[i];
		dp[0]=num[0];
		for(int i=0;i<n-1;i++) dp[i+1]=max(num[i+1],num[i+1]+dp[i]);
		for(int i=0;i<n;i++) ans=max(ans,dp[i]);
		cout<<ans<<endl;
	}
}

C++: #include <stdio.h>
#include <string.h>

int n ;
int p ;
int q ;
int numlist[5010] ;
bool changed ;
bool vis[5010] ;

void proc ( ) ;

int main ( )
{
	while ( scanf ( "%d" , &n ) == 1 && n ) {
		for ( int i = 0 ; i < n ; i++ ) {
			scanf ( "%d" , &numlist[i] ) ;
		}
		p = 0 ;
		q = n - 1 ;
		changed = true ;
		memset ( vis , false , sizeof ( false ) ) ;
		while ( numlist[p] <= 0 ) {
			p++ ;
		}
		while ( numlist[q] <= 0 ) {
			q-- ;
		}
		while ( changed == true && p < q ) {
			changed = false ;
			proc ( ) ;
		}
		int total = 0 ;
		for ( int i = p ; i <= q ; i++ ) {
			total += numlist[i] ;
		}
		printf ( "%d\n" , total ) ;
	}
	return 0 ;
}

void proc ( )
{
	for ( int i = p ; i <= q ; i++ ) {
		if ( numlist[i] < 0 && vis[i] == false ) {
			vis[i] = true ;
			int tmp = 0 ;
			for ( int j = p ; j < i ; j++ ) {
				tmp += numlist[j] ;
			}
			if ( tmp < numlist[i] * ( -1 ) ) {
				p = i + 1 ;
				changed = true ;
			}
			break ;
		}
	}
	for ( int i = q ; i >= p ; i-- ) {
		if ( numlist[i] < 0 && vis[i] == false ) {
			vis[i] = true ;
			int tmp = 0 ;
			for ( int j = q ; j > i ; j-- ) {
				tmp += numlist[j] ;
			}
			if ( tmp < numlist[i] * ( -1 ) ) {
				q = i - 1 ;
				changed = true ;
			}
			break ;
		}
	}
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

double dot(P a,P b){return real(conj(a)*b);};
double cross(P a,P b){return imag(conj(a)*b);};

int main(){
  int n;
  while(~scanf("%d",&n)){
    if(n==0)break;
    ll cur;
    cin>>cur;
    ll mx = cur;
    while(--n){
      ll x;
      cin>>x;
      cur = max(x,cur+x);
      mx = max(mx,cur);
    }
    cout<<mx<<endl;
  }
  return 0;
}

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

using namespace std;

int N;
long long K[5001],T;

int main()
{
        scanf("%d",&N);
        if (N == 0) return 0;

        T = 0;
        K[0] = 0;

        for (int i=1;i<=N;i++){
                scanf("%lld",K+i);
        }

        for (int i=1;i<=N;i++) {
                K[i] += K[i-1];
        }

        for (int i=0;i<N;i++) {
                for (int j=i+1;j<=N;j++) {
                        T = max(T,K[j]-K[i]);
                }
        }

        printf("%lld\n",T);

        main();
}

C++: #include<iostream>
#define INFTY (1<<21)
using namespace std;

void maxsequence(int n) {
    int a[n], s[n], result = -INFTY;
    for ( int i = 0; i < n; i++ ) cin >> a[i];
    s[0] = a[0];
    for ( int i = 1; i < n; i++ ) s[i] = max(a[i], a[i] + s[i - 1]);
    for ( int i = 0; i < n; i++ ) result = max(result, s[i]);
    cout << result << endl;
}

int main() {
  int n;
  while ( cin >> n ) {
      if ( n == 0 ) return 0;
      maxsequence(n);
  }
}

C++: #include <iostr;eam>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  vector<int> maxsums, a;
  int n, tmp;

  while (true) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> tmp;
      a.push_back(tmp);
    }

    for (int i = 0; i < a.size(); i++) {
      tmp = a[i];
      for (int j = i + 1; j < a.size(); j++) {
        tmp += a[j];
        if (tmp > a[i])
          a[i] = tmp;
      }
    }

    int max = a[0];
    for (int i = 0; i + 1 < a.size(); i++)
      if (max < a[i])
        max = a[i];
    maxsums.push_back(max);
    a.clear();
  }

  for (int i = 0; i < maxsums.size(); i++)
    cout << maxsums[i] << endl;
  return 0;
}

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

using namespace std;

template <typename Type>
long long Maximum_Sum_Sequence(Type N[], int size)
{
	long long max = LLONG_MIN;

	for (int i = 0; i < size; i++)
	{
		long long sum = 0;

		for (int j = i; j < size; j++)
		{
			sum += N[j];

			if (sum > max) { max = sum; }
		}
	}

	return max;
}

int main()
{
	const int DATASETS = 5000;

	int n[DATASETS], a[DATASETS][5000], c = 0;

	while (true)
	{
		cin >> n[c];

		if (n[c] == 0) { break; }

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

		c++;
	}

	for (int i = 0; i < c; i++)
	{
		cout << Maximum_Sum_Sequence(a[i], n[i]) << endl;
	}

	return 0;
}