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

int main(){
	int n;
	cin >> n;
	while(n != 0){
		int a[n];
		

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

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

		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}

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

#define MAXNUM  ( 5000 )

using namespace std;

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  while ( true )
  {
    int N;
    int maxiVal = numeric_limits < int >::min ( );
    int testVal = 0;

    cin >> N;
    if ( N == 0 ) break;

    for ( int i = 0; i < N; ++i )
    {
      int __tmp;

      cin      >> __tmp;
      testVal  += __tmp;
      maxiVal   = max ( maxiVal, testVal );

      if ( testVal < 0 ) testVal = 0;
    }

    cout << maxiVal << endl;
  }

  return ( 0 );
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000],saidai=-100000;
	while(cin>>n&&n!=0){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;n>i;i++){
			for(int x=n;x>=i;x--){
				int kazu=0;
				for(int y=x;y>=i;y--){
					kazu=kazu+a[y];
				}
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}

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

int item[1000];
int num = 0;

// ????????????????§???????MAX????¶?????????¨??´??°??????
int GetMax(){
  int max_sum = 0;
  for(int i = 0; i < num; i++){
    int sum = 0;
    for(int j = i; j < num; j++){
      sum += item[j];
      max_sum = max(max_sum, sum);
    }
  }
  return max_sum;
}
  
void GetItem(){
  cin >> num;
  for(int i = 0; i < num; i++){
    cin >> item[i];
  }
}

int main(){
  while(true){
    GetItem();
    if(num == 0) { break; }
    cout << GetMax() << endl;
  }
}

C++: #include<stdio.h>
#define INF -1000000000
int ar[5000];
int d[5001];

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){
	int n,i,j;
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		for(i=0;i<n;i++){
			scanf("%d",&ar[i]);
		}
		d[0]=0;
		int ans=INF;
		for(i=1;i<n+1;i++)d[i]=d[i-1]+ar[i-1];
		for(i=0;i<n;i++)for(j=i+1;j<n+1;j++){
			ans=max(ans,d[j]-d[i]);
		}
		printf("%d\n",ans);
	}
}

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

int main(){
    int n;
    while(cin>>n && n!=0){
        int* A=new int[n];
        int* S=new int[n+1];
        S[0]=0;
        for(int i=0;i<n;++i){
            cin>>A[i];
            S[i+1]=A[i]+S[i];
        }

        int maxsum=A[0];
        for(int i=0;i<n;++i){
            for(int j=i+1;j<n+1;++j){
                maxsum=((S[j]-S[i])>maxsum?(S[j]-S[i]):maxsum);
            }
        }

        cout<<maxsum<<"\n";
        delete[] A;
        delete[] S;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)

int a[5010];
long long int s[5010];
int main(void){
    int n;
    while(cin >> n && n) {
        rep(i, n) cin >> a[i];
        s[0] = 0;
        rep(i, n) s[i+1] = a[i]+s[i];
        long long int ans = numeric_limits<long long int>::min();
        rep(i, n+1) {
            for(int j=i+1; j<n+1; ++j) {
                ans = max(ans, s[j]-s[i]);
            }
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
using namespace	std;
int main(){

  for(int n;cin>>n&&n;){
    int a[5000],r;
    cin>>a[0];
    r=a[0];
    for(int i=1,b;i<n;i++){
      cin>>b;
      a[i]=a[i-1]+b;
      r=max(r,max(a[i],b));
    }
    for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) r=max(r,a[j]-a[i]);
    cout<<r<<endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

using namespace std;

int main(int argc, char const* argv[])
{
    
    do {
        int n, b, maximum = -100001, current = 0;

        scanf("%d ", &n);
        if(n == 0) break;

        for (int i = 0; i < n; i++) {
            scanf("%d ", &b);
            current += b;
            if(maximum < current){
                maximum = current;
            }
            if(maximum < b){
                maximum = current = b;
            }
        }

        printf("%d\n", maximum);
    } while (1);
    
    return 0;
}

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

int main(){
int n,Sum,Ans ;

while(1){

Ans=0 ;

cin >> n ;

if(n==0){
break ;
}

vector<int> vec(n),vec2(n+1,0) ;

for(int i=0;i<n;i++){
cin >> vec.at(i) ;
}

for(int j=0;j<n;j++){
vec2.at(j+1)=vec.at(j)+vec2.at(j) ;
}

for(int k=0;k<n+1;k++){
    for(int l=k+1;l<n+1;l++){
    Sum=vec2.at(l)-vec2.at(k);
    Ans=max(Sum,Ans) ;
    }
}
cout << Ans << endl ;

}
}

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

int main()
{
    while(1){
        int n,sum=0;
        cin>>n;
        if(n==0)
            break;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }
        cout<<sum<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#define ll long long int
using namespace std;

int main()
{
  ll n,a;
  ll i,j;
  ll b[5005]={};

  while(1){
    priority_queue<int> pq;
    cin>>n;
    if(n==0)break;
    for(i=1;i<=n;i++){
      cin>>a;
      b[i]=b[i-1]+a;
      for(j=i;j>=0;j--)
	pq.push(b[i]-b[j]);
    }
    cout<<pq.top()<<endl;
  }
}

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

int maxsum(const vector<int>& data){
  int maxsumval=0,n=data.size();
  for(int i=0;i<n;i++){
    int sum=0;
    for(int j=0;j<n;j++){
      sum+=data[i+j];
      if(sum>maxsumval)maxsumval=sum;
    }
  }
  return maxsumval;

}
int main(){
  int n;
  while(cin>>n&&n){
    vector<int> data(n);
    for(int i=0;i<n;i++){
      cin>>data[i];
    }
    int maxsumval=maxsum(data);
    cout<<maxsumval<<endl;
  }

}