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++: #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;
  }


}

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

int do_stuff(int n)
{
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }

    int max_so_far = 0;
    int max_ending_here = 0;

    for (int i = 0; i < n; ++i) {
        int curr = a[i];
        max_ending_here = max(max_ending_here + curr, 0);
        max_so_far = max(max_so_far, max_ending_here);
    }

    if (max_so_far == 0) {
        max_so_far = *max_element(begin(a), end(a));
    }
    return max_so_far;
}

int main(int argc, char* argv[])
{
    //freopen("input.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    while (n != 0) {
        int ans = do_stuff(n);
        printf("%d\n", ans);
        scanf("%d", &n);
    }
    return 0;
}

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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) REP (i, 0, n)
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

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

const int INF = 1000000000;
const int MOD = 1000000007;
const double EPS = 1e-8;

int main() {
	int n;
	while (cin >> n, n) {
		int a[n], ans = -100000;
		rep(i, n) cin >> a[i];
		int sum[n + 1];
		sum[0] = 0;
		rep(i, n) sum[i + 1] = sum[i] + a[i];
		for (int i = 1; i < n + 1; ++i) {
			for (int j = i; j < n + 1; ++j) {
				// cout << sum[j] - sum[i - 1] << " ";
				ans = max(ans, sum[j] - sum[i - 1]);
			}
			// cout << endl;
		}
		cout << ans << endl;
	}
}

C++: /*
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{

	int n,q,x[1024],s[1024]={};
	long long int t;
	int *a, *d;
	freopen("C:/JOI/2016-yo/2016-yo-t4/2016-yo-t4-in2.txt","r",stdin);
	freopen("C:/Users/TAKAKO YASUMATSU/Desktop/t4/b.txt","w",stdout);
	
	cin >> n >> t >> q;

	a = new int[n];
	d = new int[n];


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

		cin >> a[i] >> d[i];

	}
	for(int i = 0; i < q; i++){

		cin >> x[i];

		s[i] = a[x[i]-1];

	}

	for(int i = 0; i < t; i++){
		for(int j = 0; j < n; j++){
			if( d[j] == 1 ){
				a[j]++;
			}
			else if( d[j] == 2 ){
				a[j]--;
			}
		}
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				if( a[j] == a[k] && j != k ){
					d[j] = 0;
				}
			}
		}
	}

	for(int i = 0; i < q; i++){
		
		cout << a[x[i]-1] << endl;
	}[
	return 0;
}
*/

#include<iostream>
#include<algorithm>
using namespace std;
int main(){

	int A[100000]={0};
	int n,MAX = -100000;

		while(1){
			MAX = -100000;

			cin >> n;

			if( n == 0 ) break;

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

				cin >> A[i];
	
			}

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

				A[i] = max(A[i],A[i] + A[i-1]);
				MAX = max(A[i], MAX);

			}
	
			cout  << MAX << endl;

		}
	return 0;
}

C++: #include <iostrem>
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 main(){
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0)break;
		int a[5100];
		for(int i=0;i<n;i++)scanf("%d",&a[i]);
		int max =-100000,sum;
        for(int j=0;j<n;j++){
            sum = 0;
            for(int k=j;k<=n-1;k++){
                sum += a[k];
                max = (max >= sum)? max:sum;}}
		printf("%d\n",max);}
		return 0;}

C++: #include <iostream>
using namespace std;int i,j,n,a[5001],m,s;main(){while(cin>>n,n){for(i=0;i<n;cin>>a[i],m=a[0],i++);for(i=0;i++<n;s=0)for(j=i;j<n;s+=a[j],j++)if(s>m)m=s;cout<<m<<"\n";}}