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>

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

		std::vector<int32_t> comfarm_list{};
		std::vector<int32_t> sum_list{};
		for( auto num : num_list )
		{
			for (auto& sum : sum_list)
			{
				if (num < 0)
				{
					comfarm_list.push_back(sum);
				}
				sum += num;
			}
			sum_list.push_back(num);
		}

		for (auto sum : sum_list)
		{
			comfarm_list.push_back(sum);
		}

		int32_t max_sum = *( std::max_element(comfarm_list.begin(),comfarm_list.end()) );
		std::cout << max_sum << std::endl;
	
		std::cin >> n;
	}

	return 0;
}

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

int main(){
  int n;
  int list[5000];

  while(cin>>n){
    if(n==0){
      break;
    }
    int temp=0;
    int max=0;
    for(int i=0; i<n; i++){
      cin >> list[i];
    }
    for(int i=0; i<n; i++){
      temp += list[i];
      if( temp<=0 ){
        temp=0;
      }
      if(max<temp){
        max=temp;
      }
    }

    cout << "output: " << max << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define loop(times) for(int i=0;i<(times);i++)

using namespace std;

int main() {
    while(1<2){
    int n;
    long long max;
    cin>>n;
    if(n==0)break;
    int a[n];
    int s[n];

    loop(n)cin>>a[i];
    max=a[0];
    s[0]=a[0];
        
    loop(n)s[i+1]=s[i]+a[i+1];
    for(int k=0;k<n;k++){
     loop(n-k){
         if(max<=s[k+i]-s[k-1])max=s[k+i]-s[k-1];   
    }
    }
    cout<<max<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
int main() {
  int n, input;
  vector<int> input_v;
  vector<int> part_v;
  int max_num = 0;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    input_v.clear();
    while(n--) {
      cin >> input;
      input_v.push_back(input);
    }
    max_num = 0;
    for (int i = 0; i < input_v.size(); ++i) {
      for (int len = 7; len <= input_v.size() - i; ++len) {
        part_v.clear();
        for (int m = 0; m < len && i + m < input_v.size(); ++m) {
          part_v.push_back(input_v[i + m]);
        }
        max_num = max(accumulate(part_v.begin(), part_v.end(), 0), max_num);
      }
    }
    cout << max_num << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
main(){
	int n;
	while(cin>>n){
		int d[n],sum=0;
		for(int i=0;i<n;++i){
			cin>>d[i];
			sum+=d[i];
		}
		for(int i=0;i<n;++i){
			int tmp=0;
			for(int j=i;j<n;++j){
				tmp+=d[j];
			}
			if(tmp>sum)sum=tmp;
			tmp=0;
			for(int j=0;j<i;++j){
				tmp+=d[j];
			}
			if(tmp>sum)sum=tmp;
			for(int j=n-1;j>=0;--j){
				tmp=0;
				for(int k=i;k<=j;++k){
					tmp+=d[k];
				}
				if(tmp>sum)sum=tmp;
			}
		}
		cout<<sum<<endl;
	}
}

C++: #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int main(void){
	while(true){
		int n;
		cin>>n;
		if(n==0)break;
		ll a[5000];
		// ll b[5000];
		// int N=0;
		// bool plus=true;
		// rep(i,n){//????????£?¶???????????¬?????????¨???????????¨??????
		// 	cin>>a[i];
		// 	if(i==0){
		// 		if(a[0]<0)plus=false;
		// 	}
		// 	if((plus && a[i]<0)||(!plus && a[i]>=0)){//?¬????????????????
		// 		N+=1;
		// 	}
		// 	b[N]+=a[i];
		// }

		rep(i,n){//????????£?¶???????????¬?????????¨???????????¨??????
			cin>>a[i];
		}
		ll max=0;
		ll current;
		rep(i,n){
			current=0;
			reg(j,i,n-1){
				current+=a[j];
				if(current>max)max=current;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

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

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){

	while(1){
		int n;
		cin>> n;
		if(!n) break;
		
		vector<int> a(n,0);
		for(int i=0;i<n;i++){
			cin>> a[i];
		}
		
		int sum = -100000;
		for(int i=0;i<n;i++){
			int sum2 = a[i];
			if(sum < sum2) sum = sum2;
			for(int j=i+1;j<n;j++){
				sum2 += a[j];
				if(sum < sum2) sum = sum2;
			}
		}
		
		cout<< sum<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

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

int main() {
  int n;
  while(cin >> n && n) {
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for(int i = 1; i < n; ++i) {
      a[i] += a[i-1];
    }
    a.insert(a.begin(), 0);
    int res = INT_MIN;
    for(int i = 0; i < n; ++i) {
      for(int j = i+1; j <= n; ++j) {
	int tmp = a[j]-a[i];
	res = max(res, tmp);
      }
    }
    cout << res << endl;
  }
  return 0;
}

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

long long int sum(const std::vector<int> &a, int begin, int end){
	long long int s = 0;
	for(int i=begin; i<end; i++){
		s += a[i];
	}
	return s;
}

int main() {
	int n;
	std::vector<int> a;
	while(std::cin >> n, n){
		for(;n--;){
			int ai;
			std::cin >> ai;
			a.push_back(ai);
		}
		long long int max_sum = sum(a, 0, a.size());
		for(int len = a.size() - 1; len--;){
			for(int begin = 0; begin < a.size() - len + 1; begin++){
				if(begin && a[begin-1] > 0)
					continue;
				if(a[begin+len] > 0)
					continue;
				long long int s = sum(a, begin, begin + len);
				if(s > max_sum){
					max_sum = s;
				}
			}
		}
		std::cout << max_sum << std::endl;
		a.clear();
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
#include<numeric>
using namespace std;


int main(void) {

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

    vector<int> a(n+1, 0);
    int sum = 0;
    for(int i=0; i<n; i++){
      int tmp;
      cin >> tmp;
      sum += tmp;
      a[i+1] += sum;
    }

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

  }

  return 0;
}