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++: #define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
using namespace std;

int main(){
	int N;
	while(cin >> N && N > 0){
		int a[N];
		REP(i,N){
			cin >> a[i];
		}

		int maximum = a[0];
        REP(i,N-1){
            int sum = 0;
            int maximum_i = 0;
            for(int j = i; j < N; j++){
					sum += a[j];
                    maximum_i = max(sum,maximum_i);
            }
            maximum = max(maximum,maximum_i);
		}
		cout << maximum << endl;
	}
}

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

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

    for(int i=0; i<n; i++){
      int sum=0;
      for(int j=i; j<n; j++){
	sum+=a[j];
	if(Max < sum) Max = sum;
      }
    }
    cout << Max << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <cstring>

using namespace std;

int main(){
	int n;
	int max,tmpmax1,tmpmax2;
	while(cin >> n && n != 0){
		max = -100001;
		int *factor = new int[n];
		
		for(int i = 0; i < n; i++){
			cin >> factor[i];
		}

		for(int i = 0; i < n - 1; i++){
			tmpmax1 = 0;
			tmpmax2 = -100001;
			for(int j = i; j < n; j++){
				tmpmax1 += factor[j];
				if(tmpmax2 < tmpmax1){
					tmpmax2 = tmpmax1;
				}
			}
			if(tmpmax2 < 0){
				for(int i = 0; i < n; i++){
					if(tmpmax2 == factor[i]){
						if(i != n - 1 && factor[i + 1] < 0){
							tmpmax2 += factor[i + 1];
							break;
						}
					}
				}
			}
			if(max < tmpmax2){
				max = tmpmax2;
			}
		}
		delete [] factor;
		cout << max << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<long int> a,b;
    for(int i=0,j; i<n; i++){
      cin >>j;
      a.push_back(j);
      if(i != 0) a[i]+=a[i-1];
    }
    b.push_back(0);
    for(int i=1; i<n; i++) b.push_back(min(b[i-1],a[i]));
    long int ans = a[0];
    for(int i=1; i<n; i++) ans = max(ans,a[i]-b[i]);
    cout <<ans<<endl;
  }
  return 0;
}

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

	long n, max=0;
	long *a;
	long sum;

	do{
		max = -1000000;
		//cout << endl;
		cin >> n;

		if (n == 0) break;

		a = new long[n + 1];

		sum = 0;

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

			sum = 0;

			cin >> a[i];

			for (int j = i; j >= 0; j--){

				sum += a[j];
				if (max < sum) max = sum;
			}
		}

		cout << max << endl;
	} while (1);
}

C++: #include<iostream>
int n[5000];
int main(){
	while(1){
		int a;
		std::cin >> a;
		if(a==0)break;
		int dp[5000];
		for(int i = 0; i < a; ++i){
			std::cin >> n[i];
		}
		int max = 0;
		dp[0]=n[0];
		for(int i = 1; i < a; ++i){
			if(dp[i-1]>0)dp[i] = dp[i-1] + n[i];
			else dp[i]=n[i];
			if(max < dp[i])max=dp[i];
		}
		std::cout<<max<<std::endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#define ll long long
#define INF (1<<30)
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		vector<ll> a(n);
		vector<ll> Sum(n+1);
		for (int i = 0; i < n; i++) cin >> a[i];
		Sum[0] = 0;
		for (int i = 1; i <= n;i++) Sum[i] = a[i-1] + Sum[i - 1];

		ll ans = -INF;

		for (int i = 0; i < n;i++) {
			for (int j = i + 1;j <= n;j++) {
				ans = max(ans,Sum[j] - Sum[i]);
			}
		}
		cout << ans << endl;
	}
}

C++: #include <stdio.h>
#include <string.h>

int n ;
int ans ;
int numlist[5010] ;

void proc ( ) ;

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

void proc ( )
{
	for ( int i = 0 ; i < n - 1 ; i++ ) {
		for ( int j = i + 1 ; j < n ; j++ ) {
			int total = 0 ;
			for ( int k = i ; k <= j ; k++ ) {
				total += numlist[k] ;
			}
			ans = ( total > ans ) ? total : ans ;
		}
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

bool solve() {
  int n;
  cin >> n;
  if (n == 0) return false;
  vector<int> a(n);
  for (int& i : a) cin >> i;
  int sum = 0, res = a[0];
  for (int i = 0; i < n; ++i) {
    res = max(res, sum + a[i]);
    if (sum + a[i] < 0) sum = 0;
    else sum += a[i];
  }
  cout << res << endl;
  return true;
}

int main() {
  while (solve());
}

C++: #define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
using namespace std;

int main(){
	int N;
	while(cin >> N && N > 0){
		cout << endl;
		int a[N];
		REP(i,N){
			cin >> a[i];
		}

		int maximum = a[0];
        REP(i,N){
            int sum = 0;
            int maximum_i = 0;
            for(int j = i; j < N; j++){
					sum += a[j];
                    maximum_i = max(sum,maximum_i);
            }
            maximum = max(maximum,maximum_i);
		}
		cout << maximum;
	}
}

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

int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0) break;
    int i,cr,max;
    cr=0;
    max=-100000;
    while(n--){
      cin>>i;
      cr +=i;
      if(cr<0) cr=0;
      if(cr>max) max=cr;
    }
    cout<<max<<endl;
  }
  return 0;
}

C++: #include<stdio.h>

int main(void) 
{
    long int num[5000];
	int cut_i;
	int kousuu;
	long int nyuryoku;
	
	while(1){
		scanf("%d",&kousuu);
		
		if(kousuu == 0){
			break;
		}

		int kou = 0;
		long int max = -100000;
		for(cut_i=0;cut_i<kousuu;cut_i++){
			num[cut_i]=0;
		}

		for(cut_i=0;cut_i<kousuu;cut_i++){
			scanf("%d",&nyuryoku);

			if(num[kou] * nyuryoku <0){
				kou++;
			}
			num[kou]+=nyuryoku;
			
			if(max<num[kou]){
				max = num[kou];
			}
		}

		kou++;
		cut_i = 0;
		
		for(cut_i=0;cut_i<kou;cut_i++){

			if(max<num[cut_i]){
				max = num[cut_i];
			}
			
			if(num[cut_i]+num[cut_i+1] > 0){
				num[cut_i+1]+=num[cut_i];
			}
		}

		printf("%d\n",max);

	}
    return 0;
}

C++: /*
	0022:Maximum Sum Sequence
*/
#include	<iostream>
#include	<algorithm>

using namespace std;

int intervalSum(int cs[], int a, int b);

int main(void) {
	while(1) {
		int n, ans;
		int array[5000], cumsum[5000] = { 0 };
		
		cin >> n;
		if(n == 0) { break; }
		
		for(int i = 0; i < n; i++) {
			cin >> array[i];
			if(i == 0) { cumsum[i] = array[i]; }
			else { cumsum[i] = array[i] + cumsum[i-1]; }
		}
		
		for(int i = 0; i < n; i++) {
			for(int j = i; j < n; j++) {
				int fl;
				if(i == j) {
					fl = array[i];
				} else if(i == 0) {
					fl = cumsum[j];
				} else {
					fl = intervalSum(cumsum, i, j);
				}
				ans = max(ans, fl);
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

int intervalSum(int cs[], int a, int b) {
	return cs[b] - cs[a-1];
}

C++: #include <iostream>
using namespace std;
int main(){
	for (;;){
		int a,goukei=0,max=-999999999,b;
		cin>>a;
		if (a==0)break;
		int data[a+1]={0};
		for (int A=1;A<=a;A++){
			cin>>data[A];
			if (max<data[A])max=data[A];
			goukei+=data[A];
			data[A]=goukei;
			if (max<data[A])max=data[A];
		}
		for (int A=3;A<a;A++){
			b=A-2;
			for (int B=b;B>0;B--){
				goukei=0;
				goukei=data[A]-data[B];
				if (goukei>max) max=goukei;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}