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

int main() {
	int n, a;
	vector<int> an;
	vector<vector<int>> AN;
	while (cin >> n) {
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> a;
			an.push_back(a);
		}
		AN.push_back(an); an.clear();
	}

	for (int i = 0; i < AN.size(); i++) {
		long long int max = 0, min = INT_MAX, MAX = 0, MIN = 0 , counter = 0, negative = 0;
		for (int j = 0; j < AN[i].size(); j++) {
			if (AN[i][j] >= 0) {
				max += AN[i][j];
				if (MAX < max)MAX = max;
				counter = 1;
				negative = 1;
			}
			
			else {
				if (negative == 0) {
						if(min > abs(AN[i][j]))min=abs(AN[i][j]);
					}
				else if (counter==1){
					if (AN[i][j] + max >= 0)max += AN[i][j];
					else {
						max = 0;
						counter = 0;
					}
				}
			}
		}
		if (negative == 0)cout << -1*min << endl;
		else cout << MAX << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    vector<int> a(n, 0); //?´??????¨
    vector<int> b(n, 0); //????????¨
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int k = n - 1;
    while (a[k] < 0)
      k--;
    b[k] = a[k];
    for (int i = k - 1; i > -1; i--) {
      if (a[i] < 0)
	continue;
      else {
	int j = i + 1;
	int s = 0; //?????????????????????????????¨
	while (a[j] < 0) {
	  s += a[j];
	  j++;
	}
	cout << "s = " << s << " " << "i = " << i << " " << "j = " << j << endl;
	if (s + b[j] >= 0)
	  b[i] += s + b[j] + a[i];
	else // if (a[i] > s + b[j])
	  b[i] += a[i];
	cout << "b[" << i << "]= " << b[i] << endl;
      }
    }
    for (int i = 0; i < n; i++)
      cout << "b[" << i << "]= " << b[i] << endl;
    int max = b[0];
    for (int i = 1; i < n; i++)
      if (max < b[i])
	max = b[i];
    cout << max << endl;
  }
}

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

int main(){
	bool flag[5000] = {false};
	int n, in[5000], ans, tmp = 0;
	
	while(true){
		cin >> n;
		if(n == 0)
			break;

		for(int i = 0; i < n; ++i){
			cin >> in[i];
			if(in[i] > 0)
				flag[i] = true;
		}//input

		for(int i = 0; i < n; ++i){
			for(int j = i + 1; j < n; ++j){
				if(flag[i] && flag[j]){
					for(int k = i; k <= j; ++k)
						tmp += in[k];
					if(tmp > ans){
						ans = tmp; 
						tmp = 0;
					}	
					else
						tmp = 0;
				}
			}
		}
		
		cout << ans << endl;//output
		
		ans = 0;
		for(int i = 0; i < n; ++i)
			flag[i] = false;//intialize
	
	}
	return 0;
}

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

int main() {
    int num;
    while (cin >> num, num) {
        vector<int> a(num);
        cin >> a[0];
        for (int i = 1; i < num; i++) {
            cin >> a[i];
            a[i] = max(a[i - 1] + a[i], a[i]);
        }
        cout << *max_element(a.begin(), a.end()) << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int n;
int sum[5000];
int ans;

void serch(int s_i,int s_ans)
{
	if(s_i==n)
		return ;
	
	s_ans+=sum[s_i];
	
	if(ans<s_ans)
		ans=s_ans;
	
	serch(s_i+1,s_ans);
}
int main()
{
	
	for(;;)
	{
		ans=-10000000;
		
		cin >> n ;
		if(n==0)
			break;
		
		for(int i=0;i<n;i++)
		{
			cin >> sum[i] ;
		}
		
		for(int i=0;i<n;i++)
		{
			serch(i,0);
		}
		
		cout << ans << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <iostream>
#include <climits>

using namespace std;

int main()
{
	int n;
	int a[5000];
	while (true)
	{
		scanf("%d", &n);
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
			scanf("%d", a+i);

		int res = -100000;
		int sum = 0;
		for (int i = 0; i < n; ++i)
		{
			if (sum < 0)
				sum = 0;

			sum = max(sum+a[i], res);
			if (sum > res)
				res = sum;
		}
		printf("%d\n", res);
	}

	return 0;
}

C++: #include<stdio.h>

int main(void)
{
  int sum;
  int n[5000];
  int a=0,i,j,x=0,k;

  while(scanf("%d",&k) != EOF){
    if(k==0)
      break;

    for(i=0; i<k; i++){
      scanf("%d",&n[i]);
    }

    x=-10000000;
    for(i=0; i<k; i++){
      sum =0; 
      for(j=i; j<k; j++){
	sum=sum+n[j];
	if(x<sum)
	  x=sum;
      }
    }
    printf("%d\n",x);
  }

  return 0;
}

C++: #include <iostream>

#include <limits>
#include <tuple>
#include <vector>

// left: [low, mid)  right: [mid, high)
template<typename T>
std::tuple<std::size_t, std::size_t, T> find_max_crossing_subarray
(const std::vector<T> &A, std::size_t low, std::size_t mid, std::size_t high) {
    std::size_t max_left = mid - 1;
    std::size_t max_right = mid;

    T left_sum = std::numeric_limits<T>::min();
    T sum = 0;
    for(std::size_t i = 1; i <= mid - low; ++i) {
        sum += A[mid - i];
        if(sum > left_sum) {
            left_sum = sum;
            max_left = mid - i;
        }
    }

    T right_sum = std::numeric_limits<T>::min();
    sum = 0;
    for(std::size_t j = mid; j < high; ++j) {
        sum += A[j];
        if(sum > right_sum) {
            right_sum = sum;
            max_right = j;
        }
    }

    return std::make_tuple(max_left, max_right + 1, left_sum + right_sum);
}

// [low, high)
template<typename T>
std::tuple<std::size_t, std::size_t, T> find_maximum_subarray
(const std::vector<T> &A, std::size_t low, std::size_t high) {
    if(high - low < 2) return std::make_tuple(low, high, A[low]);

    std::size_t mid = (low + high) / 2;
    auto left = find_maximum_subarray<T>(A, low, mid);
    auto right = find_maximum_subarray<T>(A, mid, high);
    auto cross = find_max_crossing_subarray<T>(A, low, mid, high);

    T left_sum = std::get<2>(left);
    T right_sum = std::get<2>(right);
    T cross_sum = std::get<2>(cross);

    if(left_sum >= right_sum && left_sum >= cross_sum) return left;
    else if(right_sum >= left_sum && right_sum >= cross_sum) return right;
    else return cross;
}

int main() {
    std::vector<int> A(5000);
    while(true) {
        std::size_t n;
        std::cin >> n;
        if(n == 0) break;

        for(std::size_t i = 0; i < n; ++i) std::cin >> A[i];
        std::cout << std::get<2>(find_maximum_subarray<int>(A, 0, n)) << std::endl;
    }
}

C++: #include <algorithm>
#include <iostream>
using namespace std;
int a[5010];
int main(){
	int i,n,max_so_far,max_ending_here;//maximum subarray problem
	cin>>n;
	while(n!=0){

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

		max_ending_here=0;
		max_so_far=0;
		
		for(i=0;i<n;i++){
			max_ending_here = max(0,max_ending_here + a[i]);
			max_so_far = max(max_so_far,max_ending_here);
		}
	cout << max_so_far << endl;
	cin>>n;//kousinn
	}
}

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

int main() {
	int i, j, n, a, max_so_far, max_ending_here;
	
	while (1) {
		cin >> n;
		if (n == 0)break;
		max_so_far = 0;
		max_ending_here = 0;
		for (i = 0; i < n; i++) {
			cin >> a;
			max_ending_here = max_ending_here + a;
			if (max_ending_here < 0)max_ending_here = 0;
			if (max_so_far < max_ending_here)max_so_far = max_ending_here;
		}
		cout << max_so_far << endl;

	}

	return 0;
}