Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

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

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

void solve(int n) 
{
    int seq[n];
    for (int i = 0; i < n; i++) {
        cin >> seq[i];
    }

    bool all_minus = true;
    for (int i = 0; i < n; i++) {
        if (seq[i] >= 0) {
            all_minus = false;
        }
    }
    if (all_minus) {
        int min = seq[0];
        for (int i = 1; i < n; i++) {
            min = seq[i] > min ? seq[i] : min;
        }
        cout << min << endl;
    }

    int cur_sum = seq[0];
    int cur_max = seq[0];

    for (int i = 1; i < n; i++) {
        cur_sum += seq[i];
        if (cur_sum < 0) {
            cur_sum = 0;
        } else {
            cur_max = cur_sum > cur_max ? cur_sum : cur_max;
        }
    }
    cur_max = (cur_max > cur_sum ? cur_max : cur_sum);
    cout << cur_max << endl;
}

int main(void)
{
    int n;
    while (cin >> n) {
        if (n == 0) break;
        solve(n);
    }
    return 0;
}