Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

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

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        int ans[5050] = {0};
        for(int i = 0; i < n; i++){
            scanf("%d",&ans[i]);
        }
        long long int mx = -300000000;
        for(int i = 0; i < n; i++){
            long long int sum = 0;
            for(int j = i; j < n; j++){
                sum += ans[j];
                if(sum > mx) mx = sum;
            }
        }
        printf("%lld\n",mx);
    }
	return 0;
}

C++: #include <stdio.h>

int main() {
        int n, a;

        while (true) {
                scanf("%d", &n);
                if (!n) {
                        break;
                }

                long long sum = 0, max = -100000;
                for (int i = 0; i < n; i++) {
                        scanf("%d", &a);
                        sum += a;
                        if (sum > max) {
                                max = sum;
                        }
                        if (sum < 0) {
                                sum = 0;
                        }
                }
                printf("%lld\n", max);
        }

        return 0;
}

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

int main(){
    int n;
    cin>>n;
    while(n!=0){
        vector<int> a(n);
        for(int i=0;i<n;i++) cin>>a[i];
        vector<int> S(n+1);
        for(int i=0;i<=n;i++){
            S[i] = S[i-1] + a[i-1];
        }

        int ans =0;
        int sum =0;

        for(int i=n;i>0;i--){
            for(int j=0;j<n;j++){
                int tmp=S[i] - S[j];
                if(ans<tmp){
                    ans = tmp;
                }
            }
        }
        cout<<ans<<endl;
        cin>>n;
    }
    return 0;
}

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

using namespace std;

int main(void){

  while(1){

    int n;
    cin >> n;
    if( n == 0 ) break;
    
    int N[5000];
    for( int i = 0 ; i < n ; i++ ){
      cin >> N[i];
    }
   
    int sum = 0;
    int l = -9999999;
    for( int i = 0 ; i < n ; i++ ){
      if( sum + N[i] >= N[i] ){
	sum += N[i];
      }
      if( sum > l ){
	l = sum;
      }
    } 
    cout << l << endl;
  }
  return 0;
}

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

int main(){

  int n,count,maxu;

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

    int numbers[n];
    for(int i=0;i<n;i++)
      cin >> numbers[i];
    maxu = count = 0;

    for(int i=0;i<n;i++){
      count += numbers[i];
      maxu = max(count,maxu);
      if(count<0)
	count = 0;
    }
    if(count>0)
      maxu = max(count,maxu);

    cout << maxu << endl;

  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main( void )
{
	while (1)
	{
		int n;
		cin >> n;
		if ( n == 0 )
			break;

		int max_value = 0;
		int now = 0;
		for ( int i = 0; i < n; i++ )
		{
			int value;
			cin >> value;
			now += value;
			max_value = max( now, max_value );
			if ( now < 0 )
				now = 0;
		}

		if ( now > 0 )
			max_value = max( now, max_value );

		cout << max_value << 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);
    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 <bits/stdc++.h>
using namespace std;

int main() {
    int n,ans;
    cin >> n;
    while(n!=0){
        int a[5001];
        for(int i=0;i<n;++i){
            cin >> a[i];
        }
        ans=a[1]+a[0];
        for(int i=0;i<n-2;++i){
            ans=max(ans,a[i+2]+a[i+1]);
        }
        cout << ans << endl;
        cin >> n;
    }
}
7
-5
-1
6
4
9
-6
-7
13
1
2
3
2
-2
-1
1
2
3
2
1
-2
1
3
1000
-200
201
0

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

using namespace std;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    vector<int> a(n, 0); //?´??????¨
    vector<int> b(n, 0); //????????¨
    int s = 0; //?????????????????????????????¨
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    int k = n - 1;
    while (a[k] < 0)
      k--;
    for (int i = k - 1; i > -1; i--) {
      if (a[i] < 0)
	continue;
      else {
	int j = i;
	while (a[j] < 0) {
	  s += a[j];
	  j++;
	}
	if (s + b[j] >= 0)
	  b[i] += s + b[j + 1];
	else if (a[i] > s + b[j + 1])
	  b[i] += a[i];
      }
    }
    for (int i = 0; i < n; i++)
      cout << b[i] << endl;
    sort(b.begin(), b.end());
    cout << b[n - 1] << endl;
  }
}

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

int main(){
  int n, max_, tmp, a;
  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 <cstdio>
using namespace std;
int main(int argc, const char * argv[])
{
    while (1) {
        int n; scanf("%d", &n);
        if (n == 0) break;
        int a[n], b[n], tmp = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
            b[i] = 0;
        }
        for (int i = 0; i < n; i++) {
            for (int k = 0; k <= i; k++) {
                b[i] += a[k];
            }
        }
        for (int i = n-1; i >= 0; i--) {
            for (int k = i-1; k >= 0; k--) {
                if (i == n-1) {
                    tmp = (b[i] - b[k] + a[k]);
                }
                if (tmp < (b[i] - b[k] + a[k])) {
                    tmp = (b[i] - b[k] + a[k]);
                }
            }
        }
        cout << tmp << endl;
    }
    return 0;
}

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;
  goto label;
  return 0;
}