Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int answer[5010] = {0};
    int l = 0;
    while(cin >> number,number)
    {
        int a[5010] = {0};
        vector<int>tempmax(5010,0);
        vector<int>tempmax2(5010,0);
        REP(i,number)
        cin >> a[i];
        for(int i = number;i>=0;i--)
            for(int j = 0; j<i;j++)
            {
                tempmax[i] +=a[j];
            }
        for(int k = 0;k<number;k++)
            for(int m = k;m<number;m++)
            {
                if(k == m)
                    tempmax2[k] = a[k];
                else if(tempmax2[k]+a[m] >= tempmax2[k])
                    tempmax2[k]+= a[m];
                else
                    break;
            }
        sort(tempmax.begin(),tempmax.end(),greater<int>());
        sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        if(tempmax[0]>tempmax2[0])
            answer[l] = tempmax[0];
        else
            answer[l] = tempmax2[0];
        printf("%d\n",answer[l]);
        l++;
    }
    return 0;
}

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