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 <algorithm>
using namespace std;
int main(){
  int n;
  while( cin >> n ,n)
    {
      int a[5101] = {0};
      for(int i = 0 ; i < n ; i++ )
	{
	  cin >> a[i];
	}

      int dp[5101] = {0},mx = 0;

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

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


int main()
{
    for (int n; cin >> n && n;) {
        vector<int> sequence(n);
        int sum = 0;
        int min = 0;
        int max = numeric_limits<int>::min();
        for (int x, i = 0; i < n && cin >> x; i++) {
            sum += x;
            if (sum > max)
                max = sum;
            if (sum < min)
                min = sum;
        }
        cout << max - min << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int a[5000],n;
signed main(){
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>a[i];
        int ma=0;
        for(int i=0;i<n;i++){
            int cur=0;
            for(int j=i;j<n;j++){
                cur+=a[j];
                ma=max(ma,cur);
            }
        }
        cout<<ma<<endl;
    }

    return 0;
}

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

int main() {
	while (1) {
		int n;
		cin >> n;
		if ( n == 0 ) break;
		int a[5000];
		for ( int i = 0; i < n; i++ ) {
			cin >> a[i];
		}
		int ans = a[0];
		int pn;
		for ( int i = 0; i < n; i++ ) {
			pn = 0;
			for ( int j = 0; i + j < n; j++ ) {
				pn += a[i + j];
				if ( pn > ans ) ans = pn;
			}
		}
		cout << ans << endl;
	}
}

C++: #include <stdio.h>

#define SGN(X) ((X)>0?1:(X)<0?-1:0)
int compressRead(int a[], int n);

int main(void){
	int n;
	int a[5000];
	int max, cur;
	
	while (scanf("%d", &n), n){
		n = compressRead(a, n);
/*		printf("a[%d]:", n);
		for (int i=0; i<n; i++){
			printf("%d ", a[i]);
		}
		puts(""); */
		max = a[0];
		for (int i=0; i<n; i++){
			cur = 0;
			for (int j=i; j<n; j++){
				cur += a[j];
				if (cur > max) max = cur;
			}
		}
		printf("%d\n", max);
		for (int i=0; i<n; i++) a[i]=0;
	}
	
	return 0;
}

int compressRead(int a[], int n){
	int idx=0;
	int x,last;
	
	scanf("%d", &x);
	last=a[idx]=x;
	for (int i=1; i<n; i++){
		scanf("%d", &x);
		if (x==0) continue;
		if (x<0){
			a[++idx] = x;
//			printf("a[%d] = \%d\n",idx,x);
		}else{
			if (last<0) a[++idx]=0;
			a[idx]+=x;
//			printf("a[%d] += %d (=%d)\n", idx, x, a[idx]);
		}
		last = x;
	}
	
	return idx+1;
}

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 ;

}
}