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<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int n,sumax,temp;
	int num[5001];
	
	while(scanf("%d",&n)){
		if(n==0)
		break;
		for(int i=0;i<n;i++){
			scanf("%d",&num[i]);
		}
		sumax = 0;
		for(int i=0;i<n;i++){
			if(num[i]>sumax)
			sumax = num[i];
			temp = num[i];
			for(int j=i+1;j<n;j++){
				temp+=num[j];
				if(temp>sumax)
				sumax=temp;
			}
		}
		printf("%d\n",sumax);
	}
}

C++: #include <iostream>

using namespace std;

int main() {
	int n, *a;
	int ans, sum;
	while (1) {
		cin >> n;
		if (n == 0)
			break;
		a = new int[n];
		for (int i = 0; i < n; i++)
			cin >> a[i];
		ans = a[0];
		for (int i = 0; i < n; i++) {
			sum = a[i];
			ans = max(ans, sum);
			for (int j = i + 1; j < n; j++) {
				sum += a[j];
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
		delete[] a;
	}
	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>=i;c--){
                    for(int z=i;z<=c;z++){
                        sum+=x[z];
                        maxx=max(maxx,sum);
                    }
                    sum=0;
                }
            //}
        }
        cout<<maxx<<endl;
    }
}

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

int main(void)
{
	int n;
	long long num, sum = 0, max = -100001;
	
	scanf("%d",&n);
	for(int f1 = 0; f1 < n; f1++){
		scanf("%lld",&num);
		sum += num;
		if(max < sum)
		{
			max = sum;
		}
	}

	printf("%lld\n", max);
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main() {
	int a, i, j, k, n;
	long long max, sum;
	vector<int> s;
	while (cin >> n) {
		if (n == 0)break;
		s.clear();
		max = -100000;
		for (i = 0; i < n; i++) {
			cin >> a;
			s.push_back(a);
		}
		for (j = 0; j < n; j++) {
			sum = 0;
			for (k = j; k < n; k++) {
				sum += s[k];
				if (sum > max)max = sum;
			}
		}
		cout << max << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
if(n==0)
{
	break;
}
else
{
int a[n];
int A=0;
int R=-100000;
for(int h=0;h<n;h++)
{
	cin>>a[h];
}
for(int i=0;i<n;i++)
{
	for(int j=0;j<n-i;j++)
	{
	for(int k=i;k<=j;k++)
	{
		A=A+a[k];
		
	}	
	if(R<A)
	{
		R=A;
	}
	A=0;
	}
}
cout<<R<<endl;
}
return 0;
}

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];
		}

		sort(a.begin(), a.end());
		int sum = 0;
		for(int i = 0; i < n; i++){
			if(a[n-1-i] > 0){
				sum += a[n-1-i];
			}else{
				cout << sum << endl;
				break;
			}
		}
		cin >> n;
	}

	return 0;
}

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

int main() {
    unsigned int n, i;
    int ai;
    std::vector<int> a;
    std::vector<int> dp;
    while (std::cin >> n && n) {
        for (i = 0; i < n; i++) {
            std::cin >> ai;
            a.push_back(ai);
        }
        dp.push_back(a.front());
        for (i = 1; i < n; i++) {
            dp.push_back(std::max(dp[i - 1] + a[i], a[i]));
        }
        std::cout << *std::max_element(dp.begin(), dp.end()) << std::endl;
        a.clear();
        dp.clear();
    }
    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+1,0) ;

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

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

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

}
}

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

int main(){
  int n;
  int a[5000];
  while(cin >> n && n>0){
    for(int i=0;i>n;i++)
      cin >> a[i];
    int sum=0,tmp=0,m=-100000;
    bool flg=true;
    for(int i=0;i<n;i++){
      if(flg) m=max(m,a[i]);
      if(a[i]>0){
	flg=false;
	sum+=a[i];
	continue;
      }
      for(tmp=sum;a[i]<=0;i++){
	tmp+=a[i];
      }i--;
      if(tmp>0)
	sum=tmp;
      else
	sum=0;
    }

    cout << sum;
  }
}

C++: #include<iostream>
#include<vector>
int main()
{
	while (!std::cin.eof())
	{
		int n;
		std::cin >> n;
		if (n == 0)
		{
			break;
		}
		std::vector<int>a;
		int max = -100001;
		bool is_all_minus = true;
		for (int i = 0; i < n; i++)
		{
			int foo;
			std::cin >> foo;
			if (foo < 0 && max < foo)
			{
				max = foo;
			}
			is_all_minus &= foo < 0;
			if (i == 0 || a.back() * foo < 0 || a.back() < 0 && foo == 0 || a.back() == 0 && foo < 0)
			{
				a.push_back(foo);
			}
			else
			{
				a.back() += foo;
			}
		}
		if (!is_all_minus)
		{
			if (a.size() == 1)
			{
				max = a[0];
			}
			else
			{
				int begin = a[0] >= 0 ? 0 : 1;
				int temp_max = a[begin];
				try
				{
					for (int i = begin;;)
					{
						if (a.at(i + 1) + a.at(i + 2) > 0)
						{
							temp_max += a[i + 1] + a[i + 2];
							i += 2;
						}
						else
						{
							if (max < temp_max)
							{
								max = temp_max;
							}
							temp_max = a[i + 2];
							i += 2;
						}
					}
				}
				catch (std::out_of_range)
				{
					if (max < temp_max)
					{
						max = temp_max;
					}
				}
			}
		}
		std::cout << max << std::endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int data[6000];
        
        rep(i,n) cin>>data[i];
        
        ll maxi=-999999999999;
        
        for(int i=0;i<n;i++){
            ll sum[6000]={};
            sum[i]=data[i];
            maxi=max(maxi,sum[i]);
            
            for(int j=i+1;j<n;j++){
                sum[j]=sum[j-1]+data[j];
                maxi=max(maxi,sum[j]);
            }

        }
        
        
        cout<<maxi<<endl;
    }
}