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++: 
class Max
  def solve
    loop do
      n = get.chomp.to_i
      break if n == 0
      
      max = -100000
      sum = 0
      n.times do
        a = gets.chomp.to_i
        sum += a
        if max < sum
          max = sum
        end
        if sum < 0 then 
          sum = 0
        end
      end
      puts max
    end
  end
end
max.new.solve

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){
	long 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<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main(){

    while(1){
    int n; cin >> n;
    if(!n) break;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(i > 0) a[i] += a[i - 1];
    }
    a[0] = 0;
    int ans = a[1];
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j <= n; j++){
            ans = max(ans, a[j] - a[i]);
        }
    }

    cout << ans << endl;
    }
    return 0;
}

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

int main()
{
	int n;
	while (cin >> n, n)
	{
		long int ary[5001] = {};

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

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

	return 0;
}

C++: //Maximum Sum Sequence
#include<bits/stdc++.h>
using namespace std;

int main(){
  while(true){
    int n, max=0, tmp=0;
    cin>>n;
    if(n==0)break;
    for(int i=0; i<n; i++){
      int d;
      cin>>d;
      tmp=(tmp>0 ? tmp+d : d);
      if(max<tmp)max=tmp;
    }
    cout<<max<<endl;
  }
  return 0;
}

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

using namespace std;

long long int keisan(int start, int end, vector<int> hyou) {
	long long int sum = 0;
	for (int i = start; i <= end; i++) {
		sum += hyou[i];
	}
	return sum;
}

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<int> hyou(n);
		for (int i = 0; i < n; i++) {
			cin >> hyou[i];
		}
		long long int sum;
		long long int MAX = keisan(0, 0, hyou);
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				sum = keisan(i, j, hyou);
				MAX = max(sum, MAX);
			}
		}
		cout << MAX << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int n,k[5000],max;
  while(1){
  cin >> n;
  if(n==0)break;
  for(int i=0;i<n;i++){
    cin >> k[i];
  }
  max=0;
  int sum=0;
  for(int i=0;i<n;i++,sum=0){
    for(int j=i;j<n;j++){
      sum += k[j];
      if(sum>max){
	max=sum;
      }
    }
  }   
  cout << max << endl;
  }
}

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

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

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

int main(){
	int n;
	cin >> n;
	while(n != 0){
		int a[n];
		

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

		int maximum = 0;
		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = i; j < n; j++){
				sum += a[j];
				maximum = max(maximum, sum);
			}
		}

		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}

C++: #include<stdio.h>

int main(void)
{
  int a[5010]={};
  int tr;
  int i,j;
  int n;
  int max;

  for(scanf("%d",&n);n;scanf("%d",&n))
    {
      for(i=0;i<5010;i++)a[i]=0;
      max=0x80000000;
      for(i=1;i<=n;i++)
        {
          scanf("%d",&tr);
          a[i]=a[i-1]+tr;
        }
      for(i=0;i<n;i++)
        for(j=i;j<=n;j++)
          {
            tr=a[j]-a[i-1];
            if(max<tr)
              max=tr;
          }
      printf("%d\n",max);
    }

}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <iostream>
#include <climits>

using namespace std;

int main()
{
	int n;
	int a[5000];
	while (true)
	{
		scanf("%d", &n);
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
			scanf("%d", a+i);

		int res = INT_MIN;
		int sum = 0;
		for (int i = 0; i < n; ++i)
		{
			sum = max(sum+a[i], 0);
			if (sum > res)
				res = sum;
		}
		printf("%d\n", res);
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
using namespace std;
int maxsum(int x,vector<int> a){
	
	vector<int> s(x+1,0);
	int max;
	for(int i=1;i<=x;i++){
		if(s[i-1]<0)
			s[i]=a[i];
		else
			s[i]=s[i-1]+a[i];
	}
	max = *max_element(s.begin(),s.end());
	return max;
	
}

int main(){
	
	int n;
	while(cin>>n,n!=0){
		
		vector<int> a(n+1,0);
		
		for(int i=1;i<=n;i++)
			cin>>a[i];
		
		cout<<maxsum(n,a)<<endl;
	}
	
 	
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
	int n,i,num[5000];
	long long int sum[5001];
	while(1){
		sum[0] = 0;
		scanf("%d",&n);
		if(!n) break;
		for(i = 0;i < n;i++){
			scanf("%d",&num[i]);
			sum[i + 1] = sum[i] + num[i];
		}
		sort(sum,sum + n + 1);
		printf("%lld\n",sum[n] - sum[0]);
	}
	return 0;
}

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 = 2; 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>
#include <cmath>
using namespace std;
#define rep2(i,from,to) for(int i=(from); i<(to); ++(i))
#define rep(i,to) rep2(i,0,to)
int main() {
	int n;
	while(cin >> n && n) {
		int a[5001];
		int Max = -200000;
		rep(i,n) {
			cin >> a[i]; 
		}
		rep(i,n) {
			int sum = 0;
			sum += a[i];
			rep2(j,i+1,n) {
				sum += a[j];
				Max = max(Max, sum);
			}
		}
		cout << Max << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
long long int n,a[5000];
int main(){
	long long int i,j,t,tmp;
	while(cin >> n && n){
		tmp = 0;
		t = -1000000;
		for(i=0;i<n;i++){
			cin >> a[i];
		}
		for(i=0;i<n;i++){
			tmp += a[i];
			if(t < tmp) t = tmp;
			if(i!=n-1){
				for(j=i+1;j<n;j++){
					tmp += a[j];
					if(t < tmp) t = tmp;
				}
			}
			tmp = 0;
		}
		cout << t << endl;
	}
	return 0;
}