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>

using namespace std;

int main(){

  int n;


  while(cin >> n){
    if(n == 0) break;
    vector<int> V;
    int status = 1;
    int in;
    int sum = 0;
    for(int i = 0; i < n; i++){
      cin >> in;
      if(i == 0){
	if(in < 0) status = -1;
	else status = 1;

      } else {	
	if(in < 0 && status == 1){
	  status = -1;
	  V.push_back(sum);
	  sum = 0;
	}else if(in > 0 && status == -1){
	  status = 1;
	  V.push_back(sum);
	  sum = 0;
	}
      }
      sum += in;
    }

    V.push_back(sum);

    int max = -500000000;
    
    for(int i = 0; i < V.size(); i++){
      sum = 0;
      for(int j = i; j < V.size(); j++){
	sum += V[j];
	if(max < sum) max = sum;
      }
    }
    
    cout << max << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 

int main(void){  
  int n;
  while(cin>>n,n){
    int sum = 0, maxs = 0, a[10000];
    REP(i,n)
      cin >> a[i];
    FOR(i,0,n)
      FOR(j,i,n){
        sum = 0;
        FOR(k,i,j){
          sum += a[k];
        }
        maxs = max(sum, maxs);
      }
    

    cout << maxs << endl;
  }
  return 0;
}

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;
		int ans = -999999999;
		for (int i = 0; i < n; i++)
		{
			a.push_back(in());
		}
		for (int i = 1; i < n; i++)
		{
			a[i] += a[i - 1];
		}

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


	}
}

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

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		int num[5001];
		for(int i = 0; i < n; i++){
			cin>>num[i];
		}
		
		int dp[5001];
		dp[0]=num[0];
		int maxNum=(
			dp[0]);
		for(int i = 1; i < n; i++){
			dp[i]=max(num[i],dp[i-1]+num[i]);
			maxNum=max(maxNum,dp[i]);
		}
		cout<<maxNum<<endl;
		
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	while(cin >> n, n){
		int a[5000], ans = 0;
		for(int i = 0; i < n; i++) cin >> a[i];
		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = i; j < n; j++){
				sum += a[j];
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <stdio.h>

#define MAX 5000

int main(void)
{
	int i, j;
	int num[MAX];
	int n;
	int max;
	int sum_ij;
	int max_i;
	while (1) {
		scanf("%d", &n);
		if (n == 0) {
			break;
		}
		for (i = 0; i < n; i++) {
            scanf("%d",&num[i]);
        }
		max=-100000;
        for (i = 0; i < n; i++) {
        	max_i = sum_ij = num[i];
        	for (j = i + 1; j < n; j++) {
        		sum_ij += num[j];
                if (sum_ij > max_i) {
                    max_i = sum_ij;
                }
            }
            if (max_i > max) {
                max = max_i;
            }
        }

        printf("%d\n", max);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;
int main(){
  int n;
  int num[10000];
  while( cin >> n,n ){
    int max = -100001;

    for(int i = 0 ; i < n ; i++)cin >> num[i];

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

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

int main() {
  int n;
  while(cin >> n, n) {
    int x[n];
    for (int i=0; i<n; i++)
      cin >> x[i];

    int ans = 0;
    int dp[n][n];               // dp[i][j] : iツつゥツづァjツづ慊づづ個和
    for (int i=0; i<n; i++) {
      dp[i][i] = x[i];
      ans = max(ans, dp[i][i]);
      for (int j=i+1; j<n; j++) {
        dp[i][j] = dp[i][j-1] + x[j];
        ans = max(ans, dp[i][j]);
      }
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)

using namespace std;

int main(void){
	int n , a[5005] , s[5005] , m;
	while (cin >> n && n){
		REP(i,n){
			cin >> a[i];
		}
		s[0] = 0;
		FOR(i,1,n){
			s[i] = s[i-1]+a[i-1];
		}
		m=-100000;
		REP(i,n){
			FOR(j,i+1,n+1){
				if(s[j]-s[i]>m)
					m=s[j]-s[i];
			}
		}
		cout << m << endl;
	}


	return 0;
}

C++: #include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	int n;

	while (scanf("%d", &n), n) {
        int s[5001];

		for (int i = 1; i <= n; ++i) {
			int a; scanf("%d", &a);
			s[i] = a + s[i - 1];
		}

        int ma = -100000;

		for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
			ma = max(ma, s[i] - s[j - 1]);
		}

		printf("%d\n", ma);
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	while(cin >> n,n){
		vector<int> data(n);
		rep(i,n)cin >> data[i];
		int ret = 0;
		rep(i,n)ret = min(ret,data[i]);
		rep(i,n){
			int sum = 0;
			for(int j=i;j<n;j++){
				sum += data[j];
				ret = max(sum,ret);
			}
		}
		cout << ret << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a,saidai=-100000;
	while(cin>>n&&n!=0){
		int a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;n>i;i++){
				int kazu=0;
				for(int y=0;y<=i;y++){
					kazu=kazu+a[y];
				}
				if(kazu>saidai){
					saidai=kazu;
				}
		}
		cout<<saidai<<endl;
	}
}