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 <stdio.h>

int main(){
	int n;
	int buf[5000];
	long goukei;
	long max;
	
	int i,j;
	
	while(1){
		goukei = 0;
		max = -20000;
		scanf("%d",&n);
		if(n == 0)break;
		for(i = 0;i < n;i++){
			scanf("%d",&buf[i]);
		}
		
		for(i = 0;i < n;i++){
			goukei = 0;
			for(j = i;j < n;j++){
				goukei += buf[j];
				if(goukei > max){
					max = goukei;
				}
			}
		}
		
		printf("%d\n",max);
	}
	
	return 0;
}

C++: #include<iostream>
#include<cstring>
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
    int n;
    while(cin >> n &&n)
    {
        if(n==0)break;
        long int s[N];
        //memset(s,0,sizeof(int)*N);
        int t;
        long int max = 0;
        long int min = 0;
        for(int i=0;i<n;i++){
            cin >>t;
            s[i+1] = s[i]+t;
            if(max<s[i+1])max = s[i+1];
            if(min>s[i+1])min = s[i+1];
        }
        cout << max -min << endl;

    }

    return 0;
}

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

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

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

int main(void){
	int N;
	while (cin >> N, N) {
		vector<int> a(N);
		for (int i = 0; i < N; i++)
			cin >> a[i];
		vector<int> sums;
		sums.push_back(0);
		partial_sum(a.begin(), a.end(), back_inserter(sums));

		int m = INT_MIN;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				m = max(m, sums[j + 1] - sums[i]);
			}
		}

		cout << m << endl;
	}
}

C++: #include <iostream>
using namespace std;
int main(){
  int a,n;
  long max,sam;
  while(cin>>a,0!=a){
    cin>>n;
    max=sam=n;
    for(int i=0;i<a-1;i++){
      cin>>n;
      if(sam<0)sam=n;
      else{
        sam+=n;
      }
      if(sam>max)max=sam;
    }
    cout<<max<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

const int INF = 1e+9 * 2;

int main() {
	int n;
	while(cin >> n && n){
		int a[5010] = {0};
		for(int i = 0; i < n; ++i)
			scanf("%d", &a[i]);
		int ans = -INF;
		for(int i = 0; i < n; ++i){
			int sum = 0;
			for(int j = i; j < n; ++j){
				sum += a[j];
				if(ans < sum)
					ans = sum;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
int main(){
	int n;
	while(std::cin >> n, n){
		std::vector<int> v;
		for(int i=0;i<n;i++){
			int a;
			std::cin >> a;
			v.push_back(a);
		}

		int max = v[0];
		for(int i=0;i<n;i++){
			int k = 0;
			for(int j=i;j<n;j++){
				k += v[j];
				if(k > max)max = k;
			}
		}

		std::cout << max << std::endl;
	}	
}

C++: #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  while(cin>>n && n!=0){
    vector<int> vec(n),sum(n);
    rep(i,n) cin>>vec[i];
    sum[0]=vec[0];
    
    for(int i=1;i<n;i++) sum[i]=vec[i]+sum[i-1];
    int ma=-1e9;
    
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        chmax(ma,sum[j]-sum[i]);
      }
    }
    
    rep(i,n) chmax(ma,sum[i]);
 
    cout<<ma<<endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> Pi;

const int INF=100000000;
const long long int INF_=1000000000000000000;

int main(){
	int N;
	while(cin >> N&&N){
		vector<int> A(N);
		REP(i,0,N) cin >> A[i];
		vector<int> s(N);
		s[0]=A[0];
		REP(i,1,N) s[i]=s[i-1]+A[i];
		lli ans=0;
		REP(i,0,N) REP(j,i+1,N) if(ans<s[j]-s[i]) ans=s[j]-s[i];
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
int n;
int a[5001];
while(1){
	cin>>n;
	if(n==0){
		break;
	}
	for (int kkk=1;kkk<=n;kkk++){
		a[kkk]=0;
	}
	for (int kk=1;kk<=n;kk++){
		cin>>a[kk];
		
	}
	int high=a[1],sum=0;
	for(int i=1;i<=n;i++){
		sum=sum+a[i];
		if(sum>=high){
			high=sum;
		}
		if(sum<=0){
			sum=0;
		
	}}
cout<<high<<endl;

}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	vector<int> v(5000);
	int n , sum=0 , max=-2000000000;
	while(cin>>n,n){
		sum=0;
		max=-2000000000;
		for(int i=0;i<n;++i){
			cin >> v[i];
		}
		for(int i=n;i>=0;--i){
			for(int j=i;j<n;++j){
			sum+=v[j];
			if(sum>max) max=sum;
			}
			sum=0;
		}
		cout << max << endl;
	}
	return 0; 
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  while(n!=0){
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a.at(i);

    vector<int> s(n+1);
    s.at(0) = 0;
    for(int i=1;i<n+1;i++) s.at(i) = s.at(i-1)+a.at(i-1);

    int ans=0;
    for(int i=1;i<=n;i++){
      for(int j=0;j<i;j++){
        ans = max(s.at(i)-s.at(j),ans);
      }
    }

    cout << ans << endl;

    cin >> n;
  }
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[1000];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}