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<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
if(n==0)
{
	break;
}
else
{
int a[n];
int r[5000];
for(int h=0;h<5000;h++)
{
	r[h]=-100001;
}
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
for(int j=0;j<n;j++)
{
	if(a[j]<0)
	{r[j]=a[j];}
	else
	{
		r[j]=a[j];
		for(int k=j+1;k<n;k++)
		{
			if(a[k]<0)
			{
				break;
			}
			else
			{
				r[j]+=a[k];	
			}
		}
		
	}
}
int l=0;
	while(r[0]!=-100001)
	{
		if(r[l]>r[0])
		{
			r[0]=r[l];
			l++;
		}
	}
}
return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
    ll n;
    cin >> n;
    while(n!=0){
        vector<ll> vec(n);
        for(ll i=0;i<n;i++){
            cin >> vec.at(i);
        }
        vector<ll> rsw(n+1);
        rsw.at(0) = 0;
        for(int i=1;i<n+1;i++){
            rsw.at(i) = rsw.at(i-1) + vec.at(i-1);
        }
        ll ans = vec.at(0);
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                if(ans < rsw.at(j+1)-rsw.at(i)){
                    ans = rsw.at(j+1) - rsw.at(i);
                }
            }
        }
        cout << ans << endl;
        cin >> n;

    }
}

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

int main(){
	int n, max1, max2, a[5001];

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

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

C++: #include<algorithm>
#include<iostream>
#define INF -11111111
using namespace std;
int main(){
  int n;
  int a[5555]; // 配列
  while(1){
    int ret = INF,sum;
    cin >> n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    for(int i=0;i<n;i++){
      sum = 0;
      for(int j=i;j<n;j++){
	sum += a[j];
	ret = max( ret , sum );
      }
    }
    cout << ret << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>
using namespace std;
typedef  long long int lint;
//typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define P pair<int,int>

int main() {
	while (1) {
		int N;
		cin >> N;
		if (N == 0) {
			return 0;
		}
		vector<lint>A(N);
		rep(i, N) {
			cin >> A[i];
		}
		vector<lint>S(N);
		S[0] = A[0];
		for (int i = 1; i < N; i++) {
			S[i] = S[i - 1] + A[i];
		}
		reverse(S);
		S.push_back(0);
		reverse(S);
		lint ans = -10000000000;
		for (int i = 1; i < N + 1; i++) {
			for (int j = 0; j < N + 1; j++) {
				if (j < i) {
					ans = max(ans, S[i] - S[j]);
				}
			}
		}
		cout << ans << endl;
	}
}

C++: #include <cstdio>
#include <cstring>

int main(void)
{
    int n;
    int num[5001];
    int sum;
    int max;
    
    while (scanf("%d", &n)){
        if (n == 0) break;
        
        memset(num, 0, 5001);
        for (int i = 0; i < n; i++){
            scanf("%d", &num[i]);
        }
        max = num[0];
        
        for (int i = 0; i < n; i++){
            sum = 0;
            for (int j = i; j < n; j++){
                sum += num[j];
                if (max < sum) max = sum;
            }
        }
        
        printf("%d\n", max);
    }
}

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

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<long long int> hyou(n+1, 0);
		long long int a;
		long long int MAX = 0;
		int maxn = 0;
		for (int i = 0; i < n; i++) {
			cin >> a;
			hyou[i+1] = hyou[i] + a;
			if (i == 0) {
				MAX = hyou[1];
				maxn = 1;
			} else {
				if (hyou[i+1] > MAX) {
					MAX = hyou[i+1];
					maxn = i+1;
				}
			}
		}
		long long int MIN = 0;
		int minn = 0;
		for (int i = 1; i < maxn; i++) {
			if (hyou[i] < 0) {
				if (hyou[i] < MIN) {
					MIN = hyou[i];
					minn = i;
				}
			}
		}
		if (minn != 0) {
			MAX -= MIN;
		}
		cout << MAX << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int a[5000];
int b[5000][5000];
int main() {
	int n;
	while (cin >> n&&n != 0) {
		int sum = -100000;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (i == 0) {
				b[0][i] = a[i];
				if (sum < b[0][i])
					sum = b[0][i];
			}
			else {
				b[0][i] = b[0][i - 1] + a[i];
				if (sum < b[0][i])
					sum = b[0][i];
			}
		}
		
		for (int j = 1; j < n; j++) {
			for (int i = j; i < n ; i++) {
				b[j][i] = b[j - 1][i] - a[j - 1];
				if (sum < b[j][i])
					sum = b[j][i];
			}
		}
		cout << sum << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <numeric>	// require accumulate

using namespace std;

int main()
{
	string str = "";
	int n;

	while (1){
		getline (cin, str );
		stringstream ssn(str);
		ssn >> n;

		if (n == 0){
			break;
		} // end if

		vector <int> a(n + 1, 0 );
		vector <int> sum (n + 1, 0 );
		int i,j;

		for (i = 1; i <= n; ++i){
			getline (cin, str );
			stringstream ss(str);
			ss >> a[i];
		} // end for

		for (i = 1; i <= n; ++i){
			sum[i] = accumulate (a.begin(), a.begin() + i + 1, 0 );
		} // end for

		int maxn = 0;
		for (i = 1; i <= n; ++i){
			for (j = i; j <= n; ++j){
				 maxn = max (maxn , sum[j] - sum[i - 1] );
			} // end for
		} // end for

		cout << maxn << endl;			

	} // end while

	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=k[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<vector>
#include<algorithm>

using namespace std;

int main(void){
	int Max, Num = 0, In;
	while (true){
		vector<int>	Dat;
		Max = -100000;
		cin >> Num;
		if (Num == 0)break;
		Dat.push_back(-100000);
		for (int i = 0; i < Num; i++){
			cin >> In;
			Dat.push_back(In);
		}
		for (int i = 1; i < Num + 1; i++){
			Dat[i] = max(Dat[i], Dat[i - 1] + Dat[i]);
			Max = max(Max, Dat[i]);
		}
		cout << Max << endl;
	}
	return 0;
}