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>

int maxSum(int *a, int n) {
	int sum, max = a[0];
	for (int num = 1; num <= n; ++num) {
		for (int i = 0; i < n - num + 1; ++i) {
			sum = 0;
			for (int j = 0; j < num; ++j) {
				sum += a[i + j];
			}
			if (sum > max) { max = sum; }
		}
	}
	return max;
}

int main() {
	int n;
	int *a;
	for (;;) {
		std::cin >> n;
		if (n <= 0) { break; }
		a = new int[n];
		for (int i = 0; i < n; ++i) {
			std::cin >> a[i];
		}
		std::cout << maxSum(a, n) << '\n';
		delete [] a;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
	int n;
	int a[5000]={0};
	while(cin >> n){
		int max = 0;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			cin >> a[i];
		}
		for(int i=0;i<n;i++){
			int sum = 0;
			for(int j=0;i+j<n;j++){
				sum += a[i+j];
				if(max < sum) max = sum;
			}
		}
		cout << max << "\n";
	}
	return 0;
}

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

int main(){

  int n,a[10000],ans,c;

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

    ans = a[0];

    for(int i=0;i<n;i++){
      c = 0;
      for(int j=i;j<n;j++){
	c += a[j];
	ans = max(ans,c);
      }
    }

    cout << ans << endl;

  }
}

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

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)
		{
			max = -100001;
			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 == -100001)
					{
						max = temp_max;
					}
				}
			}
		}
		std::cout << max << std::endl << std::endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	long int n, m[5000] = { 0 }, max = -2147483647, temp = 0;
	while (cin>> n && n!=0){
		for (int i = 0; i < n; i++){
			cin >> m[i];
		}
		for (int i = 0; i < n; i++){
			temp = m[i];
			for (int l = i + 1; l < n; l++){
				temp += m[l];
				if (max < temp){
					max = temp;
				}
			}temp = 0;
		}
		cout << max << endl;
		max = -2147483647;
	}
	return 0;
}

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

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

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

#define MAX 1000000000
#define MIN -10000000000

#define ll long long

using namespace std;
int main() {

        ll n,k,i,j,temp,last,maxx;
        do {
            cin>>n;
            if(n==0)break;
            vector<ll> a(n);
            vector<ll> s(n+1);
            for(i=0;i<n;i++){
                cin>>a[i];
            }
            s[0]=0;
            for(i=0;i<n;i++){
                s[i+1]=s[i]+a[i];
            }
            maxx=-100000;
            for(i=0;i<n;i++){
                for(j=i;j<=n;j++){
                    maxx=max(s[j]-s[i],maxx);
                }
            }
            cout << maxx << endl;



        }while(n!=0);

//cout << "aaa" << endl;

    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
while(true)
{
int n;
cin >> n;
if(n == 0)return 0;
int numbers[n];
for(int i = 0;i < n;i++)
cin >> numbers[i];
int max = 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;
}
}

C++: #include <stdio.h>
int array[5000];
int n,i,sum=-50000,k=0;
void tansaku(int a)
{
	k += array[a];
	if(k > sum)
	{
		sum = k;
	}
	if(a == n-1)return;
	tansaku(a+1);
}
int main(void)
{
	while(1)
	{
		sum = 0;
		for(i=0;i<5000;i++)
		{
			array[i] = 0;
		}
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++)
		{
			scanf("%d",&array[i]);
		}
		for(i=0;i<n;i++)
		{
			tansaku(i);
			k = 0;
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include<stdio.h>

int main()
{
	int n;
	while(true)
	{
		scanf("%d",&n);
		if(n==0){return 0;}
		
		if( n >= 1 && n <= 5000){
		int a[5000]={0},max=-100000;
		for(int x=0;x<n;x++)
		{
			scanf("%d",&a[x]);
			if(a[x]>=10000||a[x]<=-100000)
			{
				x--;
			}
			else
			{
			for(int y=0;y<=x;y++)
			{
				if(y!=x)
				{
					a[y]+=a[x];
				}
				if(max<a[y])
				{
					max=a[y];
				}
			}
			}
		}
		printf("%d\n",max);
		}
	}
}

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

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

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

}

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

int main(){
int n,m=0;
int a[5001];
int sum;
int big=0;
while(cin>>n){
big=0;
for(int i=0;i<n;i++)cin>>a[i];

for(int i=0;i<n-1;i++){
if((a[i]>=0&&a[i+1]>=0)||(a[i]<=0&&a[i+1]<=0)){
a[i]+=a[i+1];
for(int j=i+1;j<n-1;j++)a[j]=a[j+1];
i--;
n--;}}

for(int i=1;i<n+1;i++){
for(int j=0;j<n-i;j++){
sum=0;
for(int k=0;k<i;k++){
sum+=a[j+k];}
if(sum>big){big=sum;}}}
cout<<big<<endl;}}

C++: #include <stdio.h>

int main()
{
	int a[5000];
	int n;
	long int max;
	long int dummy;
	scanf("%d",&n);
	while(n != 0){
		for(int i = 0; i < n; i++){
			scanf("%d",&a[i]);
		}
		max = a[0];
		for(int i = 0; i < n; i++){
			dummy = 0;
			for(int j = i; j < n; j++){
				dummy += a[j];
				if(dummy > max){
					max = dummy;
				}
			}
		}
		printf("%ld\n",max);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<int>in(n);
    rep(i,n)cin>>in[i];
    int max=0;
    rep(i,n){
      int sum=0;
      loop(j,i,n){
	sum+=in[j];
	if(max<sum)max=sum;
      }
    }
    cout<<max<<endl;
  }


}