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

Python: if __name__ == '__main__':
    while True:
        # ??????????????\???
        loop = int(input())
        if loop == 0:
            break
        data = [int(input()) for _ in range(loop)]

        # ???????????????
        max_total = 0  # ??£?¶?????????°???????????§????¨????
        total = 0
        for d in data:
            if d > 0:  # ??°??????+??§????????°?????±????°????
                total += d  # ????¨?????¶???????????¨?????????´??°????????????????¢????????????????
                if total > max_total:
                    max_total = total
            else:  # ??°??????-?????´?????????????????§????????£???????????????????????§??????????????????
                if total > abs(d):  # ???????????§??????????????????????????§????????°???total???????????????????¶??¶???????
                    total += d
                    # ???????????????????????????????????§???max_total?????´??°??????????????§?????????
                else:
                    total = 0  # ???????????????????????§??????????????????????????§??????????????§????¨??????????????????????????¬??????????????????????????????????

        # ???????????¨???
        print(max_total)

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

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

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

C++: // 0022.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(ll a=0;a<t;a++) 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	while (cin >> n) {
		if (n == 0) { break; }
		ll dp[5001]; ll a[5001];
		ll ans = -9000000000;
		roop(i, n) {
			cin >> a[i];
			
			if (i > 0) {
				dp[i] = max(dp[i - 1] + a[i], a[i]);
			}
			else {
				dp[i] = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			ans = max(dp[i],ans);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>

int main(){
  int n;
  int temp,max,a;

  while(1){
    std::cin >> n;
    if(n==0){
      break;
    }
    int a[n];
    for(int i=0;i<n;i++){
      std::cin >> a[i];
    }
    max = a[0];
    for(int i=0;i<n;i++){
      temp = a[i];
      for(int j=i+1;j<n;j++){
        temp += a[j];
        if(max < temp){
          max = temp;
        }
      }
    }
    std::cout << max << std::endl;
  }
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#define EPS 1e-10
#define INF (-(1<<21))
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (1) {
		cin >> n;
		if (!n)break;
		vector<vector<int> >v(n, vector<int>(n));
		vector<int>a(n);
		for (int i = 0; i < n; i++)cin >> a[i];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i == j)v[i][j] = a[i];
				else v[i][j] = INF;
			}
		}
		int max = INF;
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				if (i == j) {
					//cout << v[i][j] << " ";
					continue;
				}
				v[i][j] = v[i][j - 1] + a[j];
				if (max < v[i][j])max = v[i][j];
				//cout << v[i][j] << " ";
			}
			//cout << endl;
		}
		cout << max << endl;
	}
	return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

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

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

using namespace std;

int main()
{
	int n;

	while (scanf("%d", &n), n) {
        int s[5001];

		for (int i = 1; i <= n; ++i) {
			int a; scanf("%d", &a);
			s[i] = a + s[i - 1];
		}

        int ma = -100000;

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

		printf("%d\n", ma);
	}
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    int a[5000];
    while (cin >> n && n)
    {
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        int max = a[0];
        int S[5000];
        S[0] = a[0];
        for (int i = 1; i < n; i++)
        {
            S[i] = S[i - 1] + a[i];
        }
        for (int l = 0; l < n; l++)
        {
            for (int r = l; r < n; r++)
            {
                int sum = 0;
                if (l != 0)
                {
                    sum = S[r] - S[l - 1];
                }
                else
                {
                    sum = S[r];
                }

                if (sum > max)
                {
                    max = sum;
                }
            }
        }
        cout << max << endl;
    }
}

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

int main(){
	int n,a[5000],s,ans;
	
	while(1){
		cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i] ;
	}
		if(n==0){
			break;
		}
	ans=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			s=0;
			for(int k=j;k<j+i;k++){
				s+=a[k];
			}
			if(ans<s){
				ans=s;
			}
		}
	}
	cout << ans << "\n" ;
	}
return 0;
}

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

int main(){
  int n;
  int a[5000];
  while(cin >> n && n>0){
    for(int i=0;i<n;i++)
      cin >> a[i];
    long long sum=0,tmp=0,ma=-100000;
    int m=-100000;
    bool flg=true;
    for(int i=0;i<n;i++){
      if(flg) m=max(m,a[i]);
      if(a[i]>0){
	flg=false;
	sum+=a[i];
	continue;
      }
      ma=max(ma,sum);
      for(tmp=sum;i<n && a[i]<=0;i++){
	tmp+=a[i];
      }i--;
      if(tmp>0)
	sum=tmp;
      else
	sum=0;
    }

    cout << (flg?m:ma) << endl;
  }
}

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

using namespace std;
int length=0;
int* sums;

int main(){
  label:
  cin>>length;
  if(length==0)return 0;
  sums=new int[length];
  
  int s=0;
  for(int i=0;i<length;i++){
    int v=0;
    cin>>v;
    s+=v;
    sums[i]=s;
  }
  int max=INT_MIN;
  for(int i=0;i<length;i++){
    for(int j=i+1;j<length;j++){
      int diff=sums[j]-sums[i];
      if(diff>max){
        max=diff;
      }
    }
  }
  cout<<max;
  cout<<"\n";
  goto label;
  return 0;
}