Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

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

C++: /*Filename: aoj0022.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

int main(){
	int n = 0;

    while(cin >> n){
    	if(n == 0){
    		break;
    	}

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

        int sum[n];
        sum[0] = a[0];
        for(int i = 1; i < n; ++i){
        	sum[i] = sum[i - 1] + a[i];
        }

        int maxSum = INT_MIN;
        int minSum = INT_MAX;
        for(int i = 0; i < n; ++i){
        	maxSum = max(maxSum, sum[i] - minSum);
        	minSum = min(minSum, sum[i]);
        }
        
        cout << maxSum << endl;
    }

	return 0;
}