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=0;
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                sum=0;
                for(int k=i;k<=j;k++){
                    sum+=a[k];
                }
                ma=max(ma,sum);
            }
        }
        cout<<ma<<endl;
    }
return 0;
}

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

int main(){
  while(true){
    int n, max=0, tmp=0;
    cin>>n;
    if(n==0)break;
    for(int i=0; i<n; i++){
      int d;
      cin>>d;
      tmp=(tmp>0 ? tmp+d : d);
      if(max<tmp)max=tmp;
    }
    cout<<max;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
using namespace std;
typedef long long llong;
typedef vector <llong> vll;

int maxv(vll &x){
	int tmp=x[0];
	for (int i=1; i<x.size(); i++)
		if (x[i]>tmp) tmp=x[i];
	return tmp;
}

int main(void){
	int n;
	vll x;
	while (cin>>n, n!=0){
		int s=LLONG_MIN;
		for (int i=0; i<n; i++){
			int n2;
			cin>>n2;

			for (int j=0; j<x.size(); j++){
				x[j] += n2;
			}
			x.push_back(n2);
			if (i==0 || n2>0) s=max(s, maxv(x));
		}
		cout<<s<<endl;
		x.clear();
	}

	return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int data[1000];
        
        rep(i,n) cin>>data[i];
        
        int dp[1000][1000]={};
        
        int maxi=-999999999;
        
        for(int i=0;i<n;i++){
            dp[i][i]=data[i];
            maxi=max( maxi , dp[i][i] );
            
            for(int j=i+1;j<n;j++){
                dp[i][j]=dp[i][j-1]+data[j];
                maxi=max( maxi , dp[i][j] );
            }
        }
        
        cout<<maxi<<endl;
    }
}

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

int main(){
	int n, max, sum, a[5001];

	while( cin >> n , n ){
		max = 0;
		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];
				max = (sum>max)? sum : max;
			}
		}
		cout << max << endl;
	}
}

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

int maxsum(const vector<int>& data){
  int maxsumval=0,n=data.size();
  for(int i=0;i<n-1;i++){
    int sum=0;
    for(int j=0;j<n-i;j++){
      sum+=data[i+j];
      if(sum>maxsumval)maxsumval=sum;
    }
  }
  return maxsumval;

}
int main(){
  int n;
  while(cin>>n&&n){
    vector<int> data(n);
    for(int i=0;i<n;i++){
      cin>>data[i];
    }
    int maxsumval=maxsum(data);
    cout<<maxsumval<<endl;
  }

}

C++: #include<stdio.h>

int main(void)
{
	int n,x,t,max,r=1;
	for(;r=1;)
	{
		scanf("%d",&n);
		t=0;
		max=0;
		int a[5000]={0},sum[5000]={0};

		for(x=1;x<=n;x++)
		{
			scanf("%d",&a[x]);
			if(a[x]==0)
			{
				r=0;
				break;
			}
			else if(a[x]>0&&a[x-1]>=0)
			{
				sum[t]+=a[x];
			}
			else if(a[x]<0&&a[x-1]<=0)
			{
				sum[t]+=a[x];
			}
			else if(a[x]>0&&a[x-1]<0)
			{
				t++;
				sum[t]+=a[x];
			}
			else if(a[x]<0&&a[x-1]>0)
			{
				t++;
				sum[t]+=a[x];
			}
		}
		if(r==0)
		{
		}
		else if(sum[0]<0)
		{
			x=1;
		}
		else
		{
			x=0;
		}
		if(r==0)
		{
		}
		else if(sum[t]<0)
		{
			t--;
		}

		int y;
		y=x;
		int b[5000][5000]={0};
		
		if(r==0)
		{
		}
		else if(x==t)
		{
			max=sum[x];
			printf("%d\n",max);
		}
		else
		{
			for(x;x<=t;x++)
			{
				for(y;y<=t;y++)
				{
					if(y==0)
					{
						b[x][y]=sum[y];
					}
					else
					{
						b[x][y]=b[x][y-1]+sum[y];
					}

					if(b[x][y]>max)
					{
						max=b[x][y];
					}
				}
			}
			printf("%d\n",max);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.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 <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

char s[10000];

int main()
{
	while(1)
	{
		int n;
		scanf("%d",&n);
		if(n == 0)
		{
			break;
		}
		long long int maxw = -10000000000000;
		long long int ms = 0;
		long long int now = 0;
		for(int i = 0; i < n; i++)
		{
			long long int w;
			scanf("%lld",&w);
			now += w;
			maxw = max(maxw,now - ms);
			ms = min(ms,now);
		}
		printf("%lld\n",maxw);
	}
	return 0;
}

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


int main()
{
	int n, a[5001];
	while (cin >> n){
		for (int i = 0; i < n; i++){
			cin >> a[i];
		}
		int maxseq = -100001;
		for (int i = 0; i < n; i++){
			int sum = 0;
			for (int j = 0; i + j < n; j++){
				sum += a[i + j];
				maxseq = max(maxseq, sum);
			}
		}
		cout << maxseq<<endl;
	}
	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>

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 = 10;

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

C++: #include <iostream>
#include <climits>
int main()
{
  while (1) {
    int n;
    std::cin >> n;
    if (n == 0) break;
    int max = -INT_MAX;
    int a[n];
    for (int i = 0;i < n; i++) {
      std::cin >> a[i];
    }
    for (int i  = 0; i < n; i++) {
      if (a[i] < 0) continue;
      int temp = a[i];
      for (int j = i + 1; j < n; j++) {
        temp += a[j];
        if (temp > max) max = temp;
      }
    }
    std::cout << max << std::endl;
  }
}