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++: /*
	0022:Maximum Sum Sequence
*/
#include	<iostream>
#include	<algorithm>

using namespace std;

int intervalSum(int cs[], int a, int b);

int main(void) {
	int n, ans;
	int array[5000], cumsum[5000] = { 0 };
	while(1) {
		
		cin >> n;
		if( cin.eof() ) { break; }
		if(n == 0) { continue; }
		
		for(int i = 0; i < n; i++) {
			cin >> array[i];
			if(i == 0) { cumsum[i] = array[i]; }
			else { cumsum[i] = array[i] + cumsum[i-1]; }
		}
		
		ans = 0;
		
		for(int i = 0; i < n; i++) {
			for(int j = i; j < n; j++) {
				int fl;
				if(i == j) {
					fl = array[i];
				} else if(i == 0) {
					fl = cumsum[j];
				} else {
					fl = intervalSum(cumsum, i, j);
				}
				ans = max(ans, fl);
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

int intervalSum(int cs[], int a, int b) {
	return cs[b] - cs[a-1];
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
main(){
  long long n,i,j,t,a[5000],max;
  while(1){
    cin >> n;
    if(n==0){
      break;
    }
    else{
      for(i=0;i<n;i++){
	cin >> a[i];
      }
      max=a[0];
      for(i=0;i<n;i++){
	for(j=i,t=0;j<n;j++){
	  t=t+a[j];
	  if(t>max){
	    max=t;
	  }
	}
      }
      cout << max  << endl;
    }
  }
}

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

using namespace std;

int main() {

	int n;
	while (cin >> n, n != 0) {
		vector<int> data(n);
		for (int& temp : data) {
			cin >> temp;
		}

		int sum_max = numeric_limits<int>::min();
		for (int i = 0; i < n; ++i) {
			int sum = 0;
			auto it2 = i;
			for (int j = i; j < n; ++j) {
				sum = sum + data[j];

				if (sum_max < sum) {
					sum_max = sum;
				}
			}
		}
		cout << sum_max << endl;
	}

	return 0;
}

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

int main() {
    int n;
    while(cin >> n) {
        if(n == 0) break;
        n++;
        int a[5010]; a[0] = 0;
        for(int i=1; i<n; i++) {
            cin >> a[i];
            a[i] += a[i-1];
        }

        int ret = 0;
        for(int i=0; i<n-1; i++) {
            for(int j=i+1; j<n; j++) {
                ret = max(a[j] - a[i], ret);
            }
        }

        cout << ret << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

int n;
int a[10000];
long long int ans = -(1 << 50);

while(true){

cin >> n;

if(n == 0) break;

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

cin >> a[i];

}

long long int sum;

for(int i = 0; i < n; i++){
sum = 0;
for(int j = i; j < n; j++){
sum += a[j];
if(sum > ans){
ans = 0;
}
}
}

cout << ans << endl;

}

return 0;

}

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

int main() {
	int n;
	while (std::cin >> n) {
		if (n == 0) break;
		std::vector<int> a;
		for (int i = 0; i < n; i++) {
			int ai;
			std::cin >> ai;
			a.push_back(ai);
		}
		int max = 0, sum = 0;
		std::vector<int>::iterator end = a.begin(), beg = a.begin();
		for (std::vector<int>::iterator itr = a.begin(); itr != a.end(); itr++) {
			sum += *itr;
			if (sum > max) {
				max = sum;
				end = itr;
			}
		}
		sum = max;
		for (std::vector<int>::iterator itr = a.begin(); itr != end; itr++) {
			sum -= *itr;
			if (sum > max) {
				max = sum;
				beg = itr;
			}
		}
		std::cout << max << std::endl;
	}

	return 0;
}

C++: #define scanf_s scanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 50//00
#define MIN -100001
#define _MAX 100
#define ABC 26
int main(void)
{
	int n, a, sum1 = MIN, sum2 = 0, sum3 = 0;
	while (1) {
		scanf_s("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; ++i) {
			scanf_s("%d", &a);
			if (sum1 + a < a) {
				sum1 = a;
				sum2 = a;
			}
			else {
				if (sum1 + a < sum1 || sum2 != sum1) {
					sum2 += a;
				}
				else if (sum1 == sum2) {
					sum1 += a;
					sum2 = sum1;
				}
				if (sum2 > sum1) {
					sum1 = sum2;
				}
			}
		}
		printf("\n%d\n\n", sum1);
		sum1 = sum2 = MIN;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
    int n, ans, sum, x[5000];
    while(1){
        cin >> n;
        if(!n) break;
        ans = -100000;
        for(int i = 0; i < n; i++){
            cin >> x[i];
        }
        for(int i = 0; i < n; i++){
            sum = 0;
            for(int j = 0; j < n; j++){
                sum += x[j];
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
}

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

int main(void){
  int n;
  long a[5000];
  long long max, tmp;

  while(cin >> n && n != 0){
    for(int i = 0; i < n; i++) cin >> a[i];
    max = a[0]; tmp = 0;

    for(int i = 0; i < n; i++){
      for(int j = i; j < n; j++){
        tmp += a[j];
        if(max < tmp) max = tmp;
      }
      tmp = 0;
    }
    cout << max << endl;
  }
  return 0;
}

C++: #include<iostream>

int main(){
  int n;
  int temp,max,a;

  while(1){
    std::cin >> n;
    if(n==0){
      break;
    }
    int a[n];
    for(int i=0;i<n;i++){
      std::cin >> a[i];
    }
    max = a[0];
    for(int i=0;i<n;i++){
      temp = a[i];
      if(max < temp){
        max = temp;
      }
      for(int j=i+1;j<n;j++){
        temp += a[j];
        if(max < temp){
          max = temp;
        }
      }
    }
    std::cout << max << std::endl;
  }
}

C++: #include <stdio.h>
int array[5000];
int n,i,sum=0,k=0;
void tansaku(int a)
{
	k += array[a];
	if(k > sum)
	{
		sum = k;
	}
	if(a == 4999)return;
	tansaku(a+1);
}
int main(void)
{
	while(1)
	{
		sum = 0;
		for(i=0;i<5000;i++)
		{
			array[i] = 0;
		}
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++)
		{
			scanf("%d",&array[i]);
		}
		for(i=0;i<n;i++)
		{
			tansaku(i);
			k = 0;
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include "iostream"
using namespace std;

int a[5000],b[5001];

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		int ma=-1<<30;
		for (int i = 0; i < n; ++i)
		{
			cin>>a[i];
			if (ma<a[i])
			{
				ma=a[i];
			}
		}
		b[0]=0;
	 	for (int i = 0; i < n; ++i)
		{
			b[i+1]=b[i]+a[i];
		}
		for (int i = 1; i <= n; ++i)
		{
			for (int j = 0; i+j <= n; ++j)
			{
				if(ma<b[i+j]-b[j])
				{
					ma=b[i+j]-b[j];
				}
			}
		}
		cout<<max(b[n-1],ma)<<"\n";
	}
	return 0;
}

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

#define MAX 1000000000
#define MIN -10000000000

#define ll long long

using namespace std;
int main() {

        ll n,k,i,j,temp,last,maxx;
        do {
            cin>>n;
            if(n==0)break;
            vector<ll> a(n);
            vector<ll> s(n+1);
            for(i=0;i<n;i++){
                cin>>a[i];
            }
            s[0]=0;
            for(i=0;i<n;i++){
                s[i+1]=s[i]+a[i];
            }
            maxx=-100000;
            for(i=0;i<n;i++){
                for(j=i+1;j<=n;j++){
                    maxx=max(s[j]-s[i],maxx);
                }
            }
            cout << maxx << endl;



        }while(n!=0);

//cout << "aaa" << endl;

    return 0;
}