Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int n ;
    cin >> n;
    while(n!=0){
      vector<int>a(n);
      vector<int>S(n+1);
      S.at(0) = 0;
      for(int i = 0;i < n;i++){
        cin >> a.at(i);
      }
      for(int i = 0;i < n;i++){
         S.at(i+1) = S.at(i) + a.at(i);
      }
      int ans = 0;
      for(int k = 0; k < n;k++){
      for(int i = 0; i < n;i++){
        if(S.at(n-k) - S.at(i+1) > ans){
          ans = S.at(n-k) - S.at(i+1);
      }
    }
  }
          cout << ans << endl;
        }
}

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

int main()
{
	
	int n = 1;
	std::cin >> n;


	while (n)
	{
		std::vector<int32_t> num_list{};

		while (n--)
		{
			int tmp = 0;
			std::cin >> tmp;
			num_list.push_back(tmp);
		}
		int32_t max_num = *(num_list.begin());
		std::vector<int32_t> sum_list{};
		for( auto num : num_list )
		{
			for (auto& sum : sum_list)
			{
				sum += num;
			}
			sum_list.push_back(num);

			int32_t tmp_max_sum = *(std::max_element(sum_list.begin(), sum_list.end()));
			if (max_num < tmp_max_sum)
			{
				max_num = tmp_max_sum;
			}
		}

		std::cout << max_num << std::endl;
	
		std::cin >> n;
	}

	return 0;
}

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

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 <algorithm>
#include <iostream>
using namespace std;

int n,s[5000+10];

int biggest(int n){
    int M=-500000000-10;
    for(int p=1;p<n;p++){
//        cout << "s[" << p << "] = " << s[p] << endl;
        if(s[p]>M) M=s[p];
        for(int q=0;q<p-1;q++){
//            cout << "s[" << p << "]-s[" << q << "] = " << s[p]-s[q] << endl;
            if(s[p]-s[q]>M) M=s[p]-s[q];
        }
    }
    return M;
}

int main(){
    int n;
    while(cin){
        cin >> n;
        if(n==0) break;
        int a[5000+10];
        for(int i=0;i<n;i++){
            cin >> a[i];
            if(i==0) s[i]=a[i];
            else s[i]=s[i-1]+a[i];
        }
        cout << biggest(n) << endl;
    }
}

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

int main()
{
	int N;
	while(cin>>N && N){
	
		vector<int> n(N), dp(N);
		for(int i=0;i<N;i++){
			cin>>n[i];
		}
		int ans = -1<<29;
		for(int i=0;i<N;i++){
			if(i-1 >= 0 && dp[i-1]>0){
				dp[i] += dp[i-1] + n[i];
			}else{
				dp[i] = n[i];
			}
			ans = max(ans, dp[i]);
		}
		
		cout<<ans<<endl;
	}
	
	
	return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
int n,dset[5000],temp=0,MINEdset[5000],max=0,h[5000],b=0;
while (1){
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                MINEdset[j]=temp;
        }
        for (int j=i;j<n;j++){
                if (max<MINEdset[j]){
                        max=MINEdset[j];
                }
        }
        h[b]=max;
        max=0;
        b++;
        temp=0;
}
max=-9999999;
for (int i=0;i<b;i++){
        if (max<h[i]){
                max=h[i];
        }
}
cout<<max<<endl;
}
return 0;
}

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

using namespace std;

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        queue<int> q;
        int ans = -100000;
        int sump = 0, sumn = 0;
        while(N--) {
            int n;
            cin >> n;
            q.push(n);
            if(n >= 0) sump += n;
            else sumn += -n;
            while(q.size() > 1 && (sump <= sumn || q.front() < 0)) {
                int np = q.front();
                if(np >= 0) sump -= np;
                else sumn -= -np;
                q.pop();
            }
            ans = max(ans, sump-sumn);
        }
        cout << ans << endl;
    }
    return 0;
}

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

int maximum_sum_seq(vector<int> &seq,int n) {
  int max_sum = seq[0];
  for(int i=0;i<n;i++) {
    int cur = 0;
    for(int j=i;j<n;j++) {
      cur += seq[j];
      max_sum = max(max_sum,cur);
    }
  }
  return max_sum;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  while(cin >> n) {
    if(n == 0) break;
    vector<int> seq(n);
    for(int i=0;i<n;i++) {
      cin >> seq[i];
    }
    cout << maximum_sum_seq(seq,n) << endl;
  }
}

C++: #include <stdio.h>

int main(void)
{
	long num[10000], sum, max;
	int n, i, j, k;
	
	while (scanf("%d", &n), n != 0){
		sum = 0;
		max = 0;
		for (i = 0; i < n; i++)scanf("%ld", &num[i]);
		for (i = 0; i < n - 1; i++){
			sum = num[i];
			for (j = i + 1; j < n; j++){
				sum += num[j];
				if (max < sum)max = sum;
			}
		}
		
		printf("%ld\n", max);
	}
	
	return (0);
}

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

C++: #include <bits/stdc++.h>

using namespace std;

int s[5001];

int main()
{
    int n;

    while (cin >> n, n) {
        memset(s, 0, sizeof(s));

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

        int ma = -1000000;

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

        cout << ma << endl;
    }
}

C++: #include <iostream>
#define INF 1e+9
using namespace std;

int main(){
	int n;
	while(cin >> n,n){
		int a,dp[5001] = {},ma = -INF;
		for(int i = 0;i <= n;i++) dp[i] = -INF;
		for(int i = 0;i < n;i++) {
			cin >> a;
			dp[i + 1] = max(a,dp[i] + a);
			ma = max(ma,dp[i + 1]);
		}
		cout << ma << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){

	int A[100000]={};
	int n,MAX = -100000;

		while(1){
			MAX = -100000;

			cin >> n;

			if( n == 0 ) break;

			for(int i = 0; i < n; i++){

				cin >> A[i];
	
			}

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

				A[i] = max(A[i],A[i] + A[i-1]);
				MAX = max(A[i], MAX);

			}
	
			cout  << MAX << endl;

		}
	return 0;
}