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>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // 「累積和」と、一つ手前までの「累積和の最小値」の差が、最大となるものを探索する
  vector<int> res;
  while(1){
    int n; cin >> n;
    if(n == 0) break;
    vector<int> a(n, 0);
    vector<int> b(n, 0);
    int c = 0, ans = -1e9;
    REP(i, n){
      cin >> a[i];
      if(i){
        b[i] = b[i-1] + a[i];
        c = min(c, b[i-1]);
        ans = max(ans, b[i] - c);
      }else{
        b[i] = a[i];
        ans = max(ans, b[i]);
      }
    }
    res.push_back(ans);
  }
  for(auto &i : res){
    cout << i << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int num[5001];

int sum(int a,int b){
  int s=0;
  for(int i=0;i<b;i++){
    s+=num[a+i];
  }
  return s;
}

int main(){
  int max;
  int n;
  
  while(cin>>n,n){
    max=0;
    for(int i=0;i<n;i++){
      cin>>num[i];
    }
    for(int i=0;i<n-1;i++){
      for(int j=2;j<=n-i;j++){
	if(max<sum(i,j))max=sum(i,j);
      }
    }
    cout<<max<<endl;
  }
}

C++: #include <iostream>

#include <vector>

#include <algorithm>

#include <sstream>

#include <string>

#include <cmath>

#include <list>

#include <set>
#include <cstdlib>
using namespace std;

int in() {int x; cin >> x; return x;}

template <typename T> class SegTree

{

public:

	int n;

	T T_max;

	vector<T> dat;

	SegTree(int n_, T t_max)

	{

		int n = 1;

		T_max = t_max;

		while (n < n_)n *= 2;

		for (int i = 0; i < 2 * n - 1; i++)dat.push_back(t_max);

	}

	void update(int k, T a)

	{

		k += n - 1;

		dat[k] = a;

		while (k > 0)

		{

			k = (k - 1) / 2;

			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);

		}

	}



	//[a,b)

	T query(int a, int b)

	{

		return _query(a, b, 0, 0, n);

	}



private:

	T _query(int a, int b, int k, int l, int r)

	{

		if (r <= a || b <= l)return T_max;

		if (a <= l && r <= b)return dat[k];

		else

		{

			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);

			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);

			return min(vr, vl);

		}

	}

};


int main()
{
	int n;
	while (cin >> n && n)
	{
		vector<int> a; a.push_back(0);
		int ans = -999999999;
		for (int i = 0; i < n; i++)
		{
			a.push_back(in());
		}
		for (int i = 1; i < n + 1; i++)
		{
			a[i] += a[i - 1];
		}

		for (int l = 0; l < n + 1; l++)
		{
			for (int r = l; r < n + 1; r++)
			{
				ans = max(ans, a[r] - a[l]);
			}
		}
		cout << ans << endl;


	}
}

C++: a

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

int main(){
	int n;
	while(cin>>n,n){
		int ans=0,a[5000],sss;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++){
			sss=a[i];
			if(sss>=ans)ans=sss;
			for(int j=i+1;j<n;j++){
				sss+=a[j];
				if(sss>=ans)ans=sss;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(){
  vector<int> v,s(1001);
  int a,b,o=0;
  while(cin>>b){
    fill(s.begin(),s.end(),0);
    o =0;
    if(b==0) break;
    else{
    for(int i=0;i<b;i++){
      cin>>a;
      v.push_back(a);
    }
      for(int i = 0; i < b; i++){
		int sum = 0;
		for(int j = i; j < b; j++){
  sum += v[j];
  s.push_back(sum);
	}
	}

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

int n;
int a[5001];

void add( int i, int x )
{	
	while( i <= n ){
		a[i] += x;
		i += i & (-i);
	}
	
	return;
}

int sum( int i )
{
	if( i == 0 ) return 0;

	int s = 0;
	while( i > 0 ){
		s += a[i];
		i -= i & (-i);
	}
	
	return s;
}

int main()
{
	while( 1 ){
		memset( a, 0, sizeof( a ) );
	
		std::cin >> n;
		if( !n ) break;
		
		for( int i = 1; i <= n; i++ ){
		 	int x;
			std::cin >> x;
			add( i, x );
		}
		
		int ans = 0;
		
		for( int i = 0; i < n; i++ ){
		 	for( int j = i + 1; j <= n; j++ ){
				ans = std::max( ans, sum( j ) - sum( i ) );
			}
		}
		
		std::cout << ans << std::endl;
	}
	
 	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        int ans[5050] = {0};
        for(int i = 0; i < n; i++){
            scanf("%d",&ans[i]);
        }
        int mx = 0;
        for(int i = 0; i < n; i++){
            int sum = 0;
            for(int j = i; j < n; j++){
                sum += ans[j];
                mx = max(mx,sum);
            }
        }
        cout << mx << endl;
    }
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  while(n!=0){
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a.at(i);

    vector<int> s(n+1);
    s.at(0) = 0;
    for(int i=1;i<n+1;i++) s.at(i) = s.at(i-1)+a.at(i-1);

    int ans=0;
    for(int i=0;i<=n;i++){
      for(int j=0;j<i;j++){
        ans = max(s.at(i)-s.at(j),ans);
      }
    }

    cout << ans << endl;

    cin >> n;
  }
}

C++: /* AOJ 0022 Maximum Sum Sequence */

#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;

void update(int i, int x);
void init();

const int MAX_N = 5000;
const int MIN_A = -100000;

int max_sum[MAX_N + 1];

int
main()
{
    for (;;) {
        int n, i;

        cin >> n;
        if (n == 0) break;

        init();
        for (i = 1; i <= n; i++) {
            int a;

            cin >> a;
            update(i, a);
        }

        cout << *max_element(max_sum + 1, max_sum + n + 1) << endl;
    }

    return 0;
}

void
update(int i, int a)
{
    max_sum[i] = max(max_sum[i - 1] + a, a);
}

void
init()
{
    max_sum[0] = 0;
}

C++: #include <iostream>

using namespace std;
int a[5000], b[5000], c[5000];

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

    if(n == 1){
      
      cout << a[0] << endl;
    }else{

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

      c[0] = b[0];
      for(int i = 1; i < n; i++){
	c[i] = min(c[i-1], b[i]);
      }

      int ans = a[0];
      for(int i = 1; i < n; i++){
	ans = max(ans, b[i] - c[i-1]);
	ans = max(ans, b[i]);
      }
      cout << ans << endl;
    }
  }
}

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

using namespace std;

int main() {
  int n;
  vector<int> datas;
  vector<int> sums;

  while (cin >> n, n != 0) {
    int input;
    for (int n_i = 0; n_i < n; n_i++) {
      cin >> input;
      datas.push_back(input);
    }
    for (int data_i = 0; data_i < n-1; data_i++) {
      sums.push_back(datas[data_i]+datas[data_i]);
    }
    cout << *max_element(sums.begin(), sums.end()) << endl;
  }

  return 0;
}