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<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 1000000000
#define EPS 1.0e-10

using namespace std;

typedef long long ll;

int n;

int main()
{
	while (cin >> n) {
		if (n == 0)return 0;
		ll d[5250];
		
		d[0] = 0;
		int a;
		for (int i = 1; i <= n; i++) {
			cin >> a;
			d[i] = d[i - 1] + a;
		}
		ll max = -INF;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < i; j++) {
				if (d[i] - d[j] > max)max = d[i] - d[j];
			}
		}
		cout << max << endl;
	}

}

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


int main(void) {

  int n;
  while(cin >> n){
    if( n == 0 ) break;

    vector<int> a(n+1, 0);
    int sum = 0;
    for(int i=0; i<n; i++){
      int tmp;
      cin >> tmp;
      sum += tmp;
      a[i+1] += sum;
    }

    int mx = a[1];
    for(int i=0; i<n+1; i++){
      for(int j=i; j<n+1; j++){
        cerr << a[j]-a[i] << " ";
        mx = max(mx, a[j]-a[i]);
      }
    }
    cout << mx << endl;

  }

  return 0;
}

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

double before_degree = 0;;

int main(void){

    int n;
    while(cin >> n,n != 0){

        int ans = 0,tmp;
        vector<int> num(5010,0);
        for(int i = 0;i < n;i++){
            cin >> num[i];
        }
        vector<int> dp(5010,0);
        dp[0] = num[0];
        ans = dp[0];
        for(int i = 1;i < n;i++){
            dp[i] = max(num[i],dp[i-1]+num[i]);
            ans = max(ans,dp[i]);
        }


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

C++: #include <iostream>
#include <stack>
#include <stdio.h>
#include <cmath>
#include <utility>
using namespace std;
int main()
{
    int n;
	while(cin>>n&&n){
		int a[5000]={},sum[5000]={},m=-1000000;
		for(int i=0;i<n;i++){
			cin>>a[i];
			sum[i+1]=sum[i]+a[i];
		}
		for(int i=0;i<n;i++){//start
			for(int j=i;j<n;j++){//end
				int tmp=sum[j+1]-sum[i];
				m=max(m,tmp);
				if(tmp<=0){i=j;break;}
				//printf("%d-%d:%d\n",i,j,tmp);
			}
		}
		cout<<m<<endl;
	}
    return 0;
}

C++: //640711C ???????????¬????????°???
//?????????????????????:Maximum Sum Sequence
//????????????????????????15?????????????????°5??????
//

#include <algorithm>
#include <iostream>
using namespace std;

int n,s[5000+10];

int biggest(int n){
    int M=-200000-10;
    for(int p=0;p<n;p++){
//        cout << "s[" << p << "] = " << s[p] << endl;
        if(s[p]>M) M=s[p];
        for(int q=0;q<p;q++){
//            cout << "s[" << p << "]-s[" << q << "] = " << s[p]-s[q] << endl;
            if(s[p]-s[q]>M) M=s[p]-s[q];
        }
    }
    return M;
}

int main(){
    int n;
    while(cin){
        cin >> n;
        if(n==0) break;
        int a[5000+10];
        for(int i=0;i<n;i++){
            cin >> a[i];
            if(i==0) s[i]=a[i];
            else s[i]=s[i-1]+a[i];
        }
        cout << biggest(n) << endl;
    }
}

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

using i64 = long long int;

i64 acc[5003]={0};

int main(){
    int n;
    while(cin >> n, n != 0){
        vector<i64> v;
        for(int i=0;i<n;++i){
            i64 a;
            cin >> a;
            v.push_back(a);
        }
        for(int i=0;i<n;++i){
            acc[i+1] = acc[i] + v[i];
        }

        i64 ans = LLONG_MIN;
        for(int i=1;i<=n;++i){
            for(int j=i;j<=n;++j){
                ans = max(ans, acc[j] - acc[i-1]);
            }
        }

        cout << ans << endl;
    }

    return 0;
}

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

int main(void)
{
    ios::sync_with_stdio(false);
    while(1) {
        int n;
        int a[5001] = {0};
        long int ans = -10000000;
        cin >> n;
        if(n == 0) break;

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

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

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int box[5001];
	int i,j;
	int sum;
	int MAX;
	while(1){
		cin>>n;
		if(n==0)	break;
		for(i=0;i<n;i++)	cin>>box[i];
		MAX=INT_MIN;
		for(i=0;i<n;i++){
			sum=box[i];
			//cout<<sum<<endl;
			MAX=max(MAX,sum);
			for(j=i+1;j<n;j++){
				sum+=box[j];
			//	cout<<sum<<endl;
				MAX=max(MAX,sum);
			}
		}
		cout<<MAX<<endl;
	}
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

int main(int argc, char const *argv[]) {
  int i,j;

  while(1){
    int n;
    cin >>n;
    if(n==0) break;

    std::vector<long> a(n+1);
    rep(i,n) scanf(" %ld", &a[i+1]);

    std::vector<long> sum(n); //a[1]~a[i]??????
    sum[0]=0;
    for(i=1; i<=n; ++i) sum[i]=sum[i-1]+a[i];

    long ans=-5000*100000-1;
    for(i=1; i<=n; ++i){
      for(j=i; j<=n; ++j){
        ans=max(ans,sum[j]-sum[i-1]);
      }
    }

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

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	int a[5000];
	while (cin >> n&&n != 0) {
	
			int sum2 = -10001;
		for (int i = 0; i<n; i++)
			cin >> a[i];
		int sum3 = -100000;
		int sum = -10001;
		for (int i = 0; i<n; i++) {
			if(a[i] < 0) goto yo;
			for (int j = 0; j <= i; j++) {
				if (a[j]<0||(j>=1&&a[j-1]<0&&(a[j-1]+a[j])<0)) goto stop;;
				sum2 = 0;
				for (int z = j; z <= i; z++) {
					sum2 += a[z];
					if (sum < sum2) {
						sum = sum2; 
					}
				}
			stop:;
			}
		yo:;
			if (sum < a[i]) sum = a[i];
			if (sum3<sum) sum3 = sum;
		}
		cout << sum3 << endl;
	}
}

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

using namespace std;
int n,a[5008];

int solve(){
  int res=0;
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      int tmp=0;
      for(int p=i;p<=j;p++){
        tmp+=a[p];
      }
      res=max(res,tmp);
    }
  }
  return res;
}

int main(){
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
    }

    printf("%d\n",solve());

  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
	long long int n,ans = 0;
	while(1){
		cin >> n;
		if(n == 0)break;

		long int a[n];

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

C++: #include <cstdio>

int ns[5001];

int max(int a,int b){return a>b?a:b;}

int main(){
  int n;
  while(scanf("%d",&n),n){
    for(int i=1; i<=n; i++)
      scanf("%d",&ns[i]);
    for(int i=2; i<=n; i++)
      ns[i]+=ns[i-1];

    int ans=-100001;
    for(int i=0; i<=n; i++)
      for(int j=0; j<i; j++)
	ans=max(ans,ns[i]-ns[j]);

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