Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
using namespace std;
int maxsum(int x,vector<long int> a){
	
	vector<long int> s(x+1,0);
	long int max;
	for(int i=1;i<=x;i++){
		if(s[i-1]<0&&s[i-1]<a[i])
			s[i]=a[i];
		else
			s[i]=s[i-1]+a[i];
	}
	max = *max_element(s.begin(),s.end());
	return max;
	
}

int main(){
	
	int n;
	while(cin>>n,n!=0){
		
		vector<long int> a(n+1,0);
		
		for(int i=1;i<=n;i++)
			cin>>a[i];
		
		cout<<maxsum(n,a)<<endl;
	}
	
 	
}

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

int main(){
	int a[5000];
	int n, m, sum;

	for (;;){
		cin >> n;
		if (n == 0) break;
		m = 0;
		for (int i = 0; i < n; i++){
			cin >> a[i];
		}
		for (int i = 0; i < n; i++){
			sum = 0;
			for (int j = i; j < n; j++){
				sum += a[j];
				m = max(sum, m);
			}
		}

		cout << m << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n,x[5001],sum=0,maxx=0;
        cin>>n;
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            cin>>x[i];
        }
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                for(int c=n-1;c>=j;c--){
                    for(int z=j;z<=c;z++){
                        sum+=x[z];
                        maxx=max(maxx,sum);
                    }
                    sum=0;
                }
            }
        }
        cout<<maxx<<endl;
    }
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
    for(;;){
        int n;
        int a[10000]={0};
        cin>>n;
        if(n==0)break;
        long long int sum=0;
        long long int ans=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++){
            sum=0;
            for(int j=i;j<n;j++){
                sum+=a[j];
                ans=max(ans,sum);
            }
        }
        cout<<ans<<endl;

    }


	return 0;
}

C++: #include<stdio.h>
int main(){
    int a;
    while(1){
        scanf("%d",&a);
        if(a==0)return 0;
        int n[5000];
        for(int i=0;i<a;i++)scanf("%d",n+i);
        int dp[5000];
        dp[0]=n[0];
        int max=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];
        }
        printf("%d\n",max);
    }
}

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

int main(void)
{
	vector<int> numbers;
	int count, tmp, ans, Max;

	while (cin >> count) {
		ans = 0;
		Max = 0;
		for (int i = 0; i < count; i++) {
			cin >> tmp;
			if (tmp + ans > 0) {
				ans += tmp;
				Max = max(Max, ans);
			}else {
				ans = 0;
			}
			numbers.push_back(tmp);
		}
		cout << Max << endl;
	}
	
	return 0;
}

C++: #include <iostream>

#define max(X,Y) ((X > Y)?X:Y)

int main(void)
{
	while(true)
	{
		int n;
		int m=0,prev=0;
		std::cin >> n;
		if(!n)
			break;

		m = prev = -1000001;
		for(int i=0; i<n; i++)
		{
			int a;
			std::cin >> a;
			prev = max( a, prev + a );
			m = max( m, prev );
		}
		std::cout << m << std::endl;
	}
	return 0;
}

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

int main() {
	int n, a;
	vector<int> an;
	vector<vector<int>> AN;
	while (cin >> n) {
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> a;
			an.push_back(a);
		}
		AN.push_back(an); an.clear();
	}

	for (int i = 0; i < AN.size(); i++) {
		long long int max = 0, MAX = 0 , counter = 0;
		for (int j = 0; j < AN[i].size(); j++) {
			if (AN[i][j] >= 0) {
				max += AN[i][j];
				if (MAX < max)MAX = max;
				counter = 1;
			}
			else {
				if (counter==1){
					if (AN[i][j] + max >= 0)max += AN[i][j];
					else {
						max = 0;
						counter = 0;
					}
				}
			}
		}
		cout << MAX << endl;
	}
	
	return 0;
}

C++: #include <stdio.h>
#define mx(a,b) (a<b?b:a)
int main() {long long i,j,k,n;while (scanf("%lld",&n)!=EOF && n) {j=i=0;while (n--) {scanf("%lld",&k);j+=k;i=mx(i,j);j=mx(j,0);} printf("%lld\n",i);} return 0;}

C++: #include <iostream>
#include <climits>
using namespace std;
int s[2];
int main(){
  int n, a;
  while(cin >> n, n){
    int ans = -(INT_MAX-1);
    for(int i = 0 ; i < n ; i++){
      cin >> a;
      if(i == 0)s[0] = a;
      else{
	s[1] = max(a, a + s[0]);
	s[0] = s[1];
      }
      ans = max(ans, s[0]);
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#define INF 1000000000
using namespace std;
int ary[5010],fn[80],ff[80],fl[80],fr[80];

int main(){
	int N;
	while(true){
		cin>>N;
		if(N==0) break;
		for(int i=0;i<N;i++){
			cin>>ary[i];
		}
		int NN=sqrt(N),NNN=(N-1)/NN+1,cnt,hog,hog2;
		for(int i=0;i<NNN;i++){
			hog=hog2=-INF;
			for(int j=NN*i;j<min(NN*(i+1),N);j++){
				for(int k=j;k<min(NN*(i+1),N);k++){
					cnt=0;
					for(int l=j;l<=k;l++){
						cnt+=ary[l];
					}
					hog=max(hog,cnt);
					if(k==min(N,NN*(i+1))-1) hog2=max(hog2,cnt);
					if(j==NN*i&&k==min(N,NN*(i+1))-1) ff[i]=cnt;
				}
				if(j==NN*i) fl[i]=hog;
			}
			fn[i]=hog;
			fr[i]=hog2;
		}
		int res=-INF;
		for(int i=0;i<NNN;i++){
			res=max(res,fn[i]);
			for(int j=i+1;j<NNN;j++){
				hog=0;
				cnt=fr[i]+fl[j];
				for(int k=i+1;k<j;k++){
					cnt+=ff[k];
				}
				res=max(res,cnt);
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int seqsum(int n){
	int a = 0;
	int b[5000];
	int c = 0;
	int s = true;
	scanf("%d", &a);
	b[0] = a;
	s = a > 0 ? 1 : -1;

	for(int i=1; i<n; ++i){
		scanf("%d", &a);
		if(s * a > 0){
			b[c] += a;
		}else{
			b[++c] = a;
			s = a > 0 ? 1 : -1;
		}
	}

	int m = b[0] < 0 ? 0 : b[0];
	int sum = m;
	for(int i=1; i<=c; ++i){
		if(sum < 0 && m < b[i]){
			sum = m = b[i];
		}else{
			sum += b[i];
			if(m < sum){
				m = sum;
			}
		}
	}
	return m;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}

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

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> num(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> num[i];
		}
		vector<int> memo(n);
		memo[0] = num[0];
		for(int i = 1; i < n; ++i)
		{
			if(memo[i - 1] + num[i] > num[i])
			{
				memo[i] = memo[i - 1] + num[i];
			}
			else
			{
				memo[i] = num[i];
			}
		}
		int max_num = -999999999;
		for(int i = 0; i < n; ++i)
		{
			if(max_num < memo[i])
			{
				max_num = memo[i];
			}
		}
		cout << max_num << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,math[5010],most,bell;
  while(1){
    cin >> n;
    if(n==0){
      break;
    }


    for(int i=0;i<n;i++){
      cin >> math[i];
    }
    most = math[0];
    for(int i=0;i<n;i++){
      bell=0;
      for(int j=i;j<n;j++){
	bell+=math[j];
	if(most<bell){
	  most=bell;
	}
      }
    }
    cout << most << endl;
  }
}