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>
using namespace std;

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

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

int main(){

    int n, k;
    int d[5555];
    while(cin >> n, n){
      
      memset(d, 0, sizeof(d));
      for(int i=1;i<=n;i++){
	cin >> k;
	d[i] = d[i-1] + k;
      }
      
      int ans = -1<<28;  
      for(int i=0;i<=n;i++){
	for(int j=i+1;j<=n;j++){
	  ans = max(ans, d[j]-d[i]);
	}
      }
      
      cout << ans << endl;
    }
}

C++: #include <stdio.h>

int main()
{
	int n, x, p;
	
	while(scanf("%d", &n) != 0){
		if (n == 0) break;
		
		int a[n];

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

		x = a[0];

		for(int i = 1; i <= n; i++){
			for(int j = 0; j < n-i+1; j++){
				p = 0;

				for(int k = 0; k < i; k++){
					p += a[j+k];
				}

				if(x < p) x = p;
			}
		}

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

	return 0;
}

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

int main() {
    int n;
    while(cin >> n) {
        if(n == 0) break;
        n++;
        int a[5010]; a[0] = 0;
        for(int i=1; i<n; i++) {
            cin >> a[i];
            a[i] += a[i-1];
        }

        int ret = 0;
        for(int i=0; i<n; i++) {
            for(int j=i; j<n; j++) {
                ret = max(a[j] - a[i], ret);
            }
        }

        cout << ret << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int log[5001] = {0};
  int n;
  while(cin >>n,n){
    int ans = -9999999;
    for(int i=0; i<n; i++){
      cin >>log[i+1];
      log[i+1]+=log[i];
    }
    for(int i=0; i<=n; i++){
      for(int j=i+1; j<=n; j++){
	if(ans < log[j]-log[i]){ans = log[j]-log[i];}
      }
    }
    cout <<ans<<endl;
  }
  return 0;
}

C++: #include<stdio.h>
main(){
	int i,j,n,a[5000];
	
	int sum = 0,max = 0,ans = 0;
	
	
	while(1){
		
		max = 0;
	
		scanf("%d",&n);
		
		if(n==0) break;
		
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		
		for(i = n - 1; (i >= 0)&&(a[i] <= 0); i--);
		
		n = i;
		
		for(i = 0; (i <= n)&&(a[i] <= 0); i++);

		
		for( ;i <= n; i++){
			
			sum = 0;
			
			for(j = i; j <= n; j++) sum += a[j];
			
			max = sum;
			
			for(j = n; j >= i; j--){
				
				sum -= a[j];
				
				if(sum > max) max = sum;
				
			}
			
			if(max > ans ) ans = max;
		}

		printf("%d\n",ans);
		
		
		sum = 0;
		max = 0;
		ans = 0;
		
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int answer[5010] = {0};
    int l = 0;
    while(cin >> number,number)
    {
        int a[5010] = {0};
        vector<int>tempmax(5010.500);
        vector<int>tempmax2(5010);
        REP(i,number)
        cin >> a[i];
        for(int i = number;i>=0;i--)
            for(int j = 0; j<i;j++)
            {
                tempmax[i] +=a[j];
            }
        for(int k = 0;k<number;k++)
            for(int m = k;m<number;m++)
            {
                if(k == m)
                    tempmax2[k] = a[k];
                else if(tempmax2[k]+a[m] >= tempmax2[k])
                    tempmax2[k]+= a[m];
                else
                    break;
            }
        sort(tempmax.begin(),tempmax.end(),greater<int>());
        sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        if(tempmax[0]>tempmax2[0])
            answer[l] = tempmax[0];
        else
            answer[l] = tempmax2[0];
        l++;
    }
    REP(i,l)
    cout << answer[i] << endl;
    return 0;
}

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

using namespace std;

#define FOR(a) for(int i = 0; i < a; i++)
#define FORR(a, b) for(int i = a; i < b; i++)

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

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

int main()
{
	int n, a[5000], i, j, k, l, sum, max;

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

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

		max = -2147483647;
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n - i; j++)
			{
				for (k = 0; k < n - i; k++)
				{
					sum = 0;
					for (l = k; l <= i; l++)
						sum += a[l];
					if (sum > max) max = sum;
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}

C++: #include <iostream>

int calcMaxSum(int amount_set);

int main()
{
    while (true) {
        int amount_set;
        std::cin >> amount_set;
        
        if(amount_set == 0) {
            break;
        }
        std::cout << calcMaxSum(amount_set) << std::endl;
    }

    return 0;
}

int calcMaxSum(int amount_set)
{
    const int MAXNUMBER = 100000;//??\????????????????????§??????

    int *data;
    data = new int[amount_set];
    int sum = 0;
    int max = -amount_set * MAXNUMBER;//??????????????????????°?????????§????????????int?????\??????
    int min = 0;//?????????min?????£?????????????????????????????????????????°???????????§???min???0????????????

    for (int number = 0; number < amount_set; number++) {
        std::cin >> data[number];//????????????????????????
        sum += data[number];// ????????´??°

        if (sum > max) {//?????§?????????????????§????????£??????
            max = sum;//?????§????????´??°
        } 
        if (sum < min) {//????°?????????????????°?????????£??????
            min = sum;//????°?????????´??°
        }
    }

    delete [] data;

    return max - min;

}

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

int main()
{

	int n, num;
	vector< int > a;

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

		int Max = -100001;

		a.push_back( 0 );

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

			cin >> num;
			a.push_back( num );

		}

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

			a[i] = max( a[i], a[i] + a[i - 1] );
			Max  = max( Max, a[i] );
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

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

int main(){
  int n;
  long long int a, max_, tmp;
  while(cin >> n){
    max_=0; tmp=0; tmp=0;
    for(int i=0; i<n; i++){
      cin >> a;
      tmp = max(0ll,tmp+a);
      max_ = max(tmp,max_);
    }
    cout << max_ << endl;
  }
  return 0;
}