Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	while (1){
		int n, a[5001] = { 0 };
		cin >> n;
		if (n == 0)break;
		a[0] = 0;
		int maxv = -10000;
		for (int i = 1; i <= n; i++)
			cin >> a[i];
		for (int i = 1; i <= n; i++){
			a[i] = max(a[i - 1] + a[i], a[i]);
			maxv = max(a[i], maxv);
			if (maxv < a[i])
				maxv = a[i];
		}
		cout << maxv << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int n, i, k;
    int data[5000];
    while (cin >> n) {
        if (n == 0) {
            break;
        }
        int pdata [5001] = {0};
        int result = -100000;
        for (i = 0; i < n; i++) {
            cin >> data[i];
        }
        for (i = 0; i < n; i++) {
            pdata[i + 1] = pdata[i] + data[i];
        }
        for (i = 0; i < n + 1; i++) {
            for (k = 0;  k < n + 1; k++) {
                if (result < pdata[i + k] - pdata[i]) {
                    result = pdata[i + k] - pdata[i];
                }
            }
        }
        cout << result << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <algorithm>
#include <cctype>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=4e8;
const double pi=acos(-1);

ll n,ans;
vector<ll> dp,num;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		ans=-inf;
		dp=vector<ll>(n);
		num=vector<ll>(n);
		for(int i=0;i<n;i++) cin>>num[i];
		dp[0]=num[0];
		for(int i=0;i<n-1;i++) dp[i+1]=max(num[i+1],num[i+1]+dp[i]);
		for(int i=0;i<n;i++) ans=max(ans,dp[i]);
		cout<<ans<<endl;
	}
}

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

int main(){
	int i, j, k, n, sum, result, head, head_before;
	int a[5000];
	while(cin >> n){
		if(n == 0){
			break;
		}
		result = 0;
		head = 0;
		head_before = 0;
		for (i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (i = 0; i < n; i++) {
			if(head > head_before){
				head_before = head;
				head += a[i];
				continue;
			}
			for (j = 1; j <= n-i; j++) {
				sum = 0;
				for (k = 0; k < j; k++) {
					sum += a[i+k];
				}
				if(result < sum){
					result = sum;
				}
			}
			head_before = head;
			head += a[i];
		}
		cout << result << endl;
	}
	return 0;
}