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

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

int main () {

int n = -1, max = 0, cum;


cin >> n;


    while (n != 0) {

    int *foo = new int [n];
    foo[n] = {0};

    for (int i = 0; i < n; i++) {

        cin >> foo [i];

        if (i == 0)
            max = foo [i];

        cum += foo[i];

        if (cum < 0)
            cum = 0;

        if (cum > max && cum > 0)
            max = cum;

        }

    cout << max << endl;

    max = 0;
    cum = 0;

    cin >> n;

    }



    return 0;

}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n; int const N = 5000;
  while(cin >> n){
    if(n == 0){return 0;}
    int  a[N],s,num,st,tmp=0;
    for(int i=0;i<n;i++)
      cin >> a[i];
    for(st = 0;st<n;st++){
      s = 0;
      for(int i = st;i<n;i++){
	s = s+a[i];
	tmp =max(s,tmp);
      }
    }
    cout << tmp<<endl;
  }
}