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

int n;
int as[100000];

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;
  
    for (int i=0; i<n; i++) {
      scanf("%d", &as[i]);
    }
  
    int l = 0;
    int r = 0;
    int cur = 0;
    int ans = as[0];
    while (l < n) {
      while (r < n && cur >= 0) {
        cur += as[r++];
        ans = max(ans, cur);
      }
  
      l = r;
      cur = 0;
    }
  
    printf("%d\n", ans);
  }
}

C++: #include<iostream>
#include<cstring>
using namespace std;
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
    long int s[N];
    int n;
    while(cin >> n &&n)
    {
        if(n==0)break;
        memset(s,0,sizeof(int)*N);
        int t;
        long int max = 0;
        long int min = 0;
        for(int i=0;i<n;i++){
            cin >>t;
            s[i+1] = s[i]+t;
            if(max<s[i+1])max = s[i+1];
            if(min>s[i+1])min = s[i+1];
        }
        cout << max -min << endl;

    }

    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
	int n;
	int a[5010];
	for(;cin>>n,n;){
		int max=0;
		int m=0;
		bool f=false;
		for(int i=0;i<n;i++){
			cin>>a[i];
			if(a[i]>0)m+=a[i],max=max<m?m:max,f=true;
			else if(a[i]+m>0)m+=a[i];
			else m=0;
		}
		if(f)cout<<max<<endl;
		else{
			int mx=-10000000;
			rep(i,n)mx=mx<a[i]?a[i]:mx;
			cout<<mx<<endl;
		}
	}
	return 0;
}

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

int main(){
  int n, a;
  long long ing max_, tmp;
  while(cin >> n){
    max_=0; tmp=0; tmp=0;
    for(int i=0; i<n; i++){
      cin >> a;
      tmp = max(0,tmp+a);
      max_ = max(tmp,max_);
    }
    cout << max_ << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>

using namespace std;


long sumarray(long *array, int idx1, int idx2);


int main(){
  int n;
  long Max, ibuf;
  long *List;

  //ifstream ifs("input.txt"); // for debug

  cin >> n;
  while(1){

    // allocate and set value //////////////////////////////
    List = new long[n];
    for(int i=0; i<n; i++) cin >> List[i];

    // solve part //////////////////////////////////////////
    Max = 0;
    for(int l=1; l<=n; l++){
      ibuf = sumarray(List, 0, l);
      if(ibuf > Max) Max = ibuf;
      for(int i=0; i<n-l; i++){
	ibuf += List[i+l] - List[i];
	if(ibuf > Max) Max = ibuf;
      }
    }

    // deallocate //////////////////////////////////////////
    delete List;

    // output //////////////////////////////////////////////
    cout << Max;

    // for next loop //////////////////////////////////////
    cin >> n;
    if(n == 0) break;
    else cout << endl;

  }
  return 0;
}


long sumarray(long *array, int idx1, int idx2){ // array[idx1] + ... + array[idx2-1]
  long ret = 0;
  for(int i=idx1; i<idx2; i++){
    ret += array[i];
  }
  return ret;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
int n;
while(true){
cin>>n;
if(n==0)
break;
int best=0;
for(int i=0;i<n;i++)
 cin>>a[i];
 
for(int start=0;start<n;start++){
 int count=0;
 for(int len=start;len<n;len++){
  count+=a[len];
  best=max(best,count);
 }
}

cout<<best<<endl;
}
return 0;   
}

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

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

int main()
{
	int a,max_ret=0;
	while(1){
		cin>>a;
		if(a==0){
			break;
		}
		int n[5000];
		for(int i=0;i<a;i++){
			cin>>n[i];
		}
		int dp[5000];
		dp[0] = n[0];
		for(int i=1;i<a;i++){
			if(dp[i-1]>0){
				dp[i] = dp[i-1] + n[i];
			}else{
				dp[i] = n[i];
			}
			max_ret = max( dp[i], max_ret);
		}
		
		cout<<max_ret<<endl;
	}
	
	
	return 0;
}

C++: #include <iostream>
#include <vector>
int main(){
	int n;
	while(std::cin >> n, n){
		std::vector<int> v;
		for(int i=0;i<n;i++){
			int a;
			std::cin >> a;
			v.push_back(a);
		}

		int max = 0;
		for(int i=0;i<n;i++){
			int k = 0;
			for(int j=i;j<n;j++){
				k += v[j];
				if(k > max)max = k;
			}
		}

		std::cout << max << std::endl;
	}	
}

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

int maxsum(const vector<int>& data){
  int maxsumval=0,n=data.size();
  for(int i=0;i<n-1;i++){
    for(int j=0;j<n-i;j++){
      int sum=0;
      for(int k=0;k<n-i;k++){
        sum+=data[i+k];
      }
      if(sum>maxsumval)maxsumval=sum;
    }
  }
  return maxsumval;

}
int main(){
  int n;
  while(cin>>n&&n){
    vector<int> data(n);
    for(int i=0;i<n;i++){
      cin>>data[i];
    }
    int maxsumval=maxsum(data);
    cout<<maxsumval<<endl;
  }

}

C++: #include <iostream>

using namespace std;

int main()
{
	int n;

	while (1)
	{
		int a[5001] = {0}, s[5001] = {0}, max = 0;

		cin >> n;
		if(n == 0)	break;

		for (int i=1; i<=n; i++)	//入力
			cin >> a[i];

		for (int i=1; i<=n; i++) {
			for (int j=1; j<=i; j++) {
				s[i] += a[j];		//s[i] = a[1]+a[2]+...+a[i]
			}
		}

		for (int i=1; i<=n; i++) {
			for (int j=n; j>=i; j--) {
				max = (max < s[j] - s[i-1]) ? s[j] - s[i-1] : max;	//区間i,jの和を求めて比較
			}
		}

		cout << max << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

// ?¨±?????????????????
#define EPS (1e-10)

int main(){
	int n;
	while(cin >> n && n != 0){
        vector<int> a(n);
        REP(i, n) cin >> a[i];
        vector<int> sum(n);
        sum[0] = a[0];
        FOR(i, 1, n) sum[i] = sum[i-1] + a[i];
        int ret = sum[0];
        FOR(i,-1, n) FOR(j,i+1, n) ret = i > -1 ? max(ret ,sum[j]-sum[i]) : max(ret ,sum[j]) ; 
        cout << ret << endl;
    }
    return 0;
}