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>

using namespace std;

long long  n, a[5010], memo[5010];

void solve(){
  memo[0] = max(0LL, a[0]);
  long long ans = 0;
  for(int i = 1 ; i < n ; i++){
    memo[i] = max(memo[i], memo[i-1]+a[i]);
    ans = max(memo[i], ans);
  }
  cout << ans << endl;
}
int main(){

  while(cin >> n, n){
    fill(memo, memo+n, 0);
    for(int i = 0 ; i < n ; i++){
      cin >> a[i];
    }
    solve();
  }
  return 0;
}

C++: #include <iostream>

using namespace std;
int a[5000], b[5000], c[5000];

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

    b[0] = a[0];
    for(int i = 1; i < n; i++){
      b[i] = b[i-1] + a[i];
    }

    c[0] = b[0];
    for(int i = 1; i < n; i++){
      c[i] = min(c[i-1], b[i]);
    }

    int ans = 0;
    for(int i = 1; i < n; i++){
      ans = max(ans, b[i] - c[i-1]);
      ans = max(ans, b[i]);
    }
    cout << ans << endl;
  }
}

C++: #include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int n;
    while(cin>>n){
        if(n==0){
            break;
        }
        int a[n],sum=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }
        cout<<sum<<endl;
    }
    return 0;
}

C++: /*AOJ 0022*/

#include<iostream>
#include<vector>
using namespace std;

int main(){

	int n;

	for(;;){

		cin>>n;

		if(n==0){
			break;
		}

		vector<int> data;
		int max=0;
		int sum=0;

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

			int tmp;
			cin>>tmp;

			data.push_back(tmp);

		}

		for(int i=0;i<n;i++){
			sum = 0;
			if(data.at(i)<0){
				continue;
			}
			for(int j=i;j<n;j++){
				sum+=data.at(j);
				if(sum>=max){
					max = sum;
				}
			}
		}
		data.clear();
		cout<<max<<endl;

	}

	return 0;
}

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

using namespace std;

int main () {
  int n;
  int sum, max_sum;

  while(cin >> n, n){
    vector<int> a;
    for(int i = 0; i < n; i++){
      int temp;
      cin >> temp;
      a.push_back(temp);
    }

    max_sum = a[0];

    for(int begin = 0; begin < n; begin++){
      sum = 0;
      for(int end = begin; end < n; end++){
        sum += a[end];
        if (max_sum < sum){
          max_sum = sum; 
        }
      }
    }

    cout << max_sum << endl;
  }
}

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

int main()
{
	int n;
	while(cin>>n){
		if(n==0) break;
		int a[n], S[n], sum=0;
		for(int i=0;i<n;++i){
			cin>>a[i];
			sum+=a[i];
			S[i]=sum;
		}

		long max=S[0];
		for(int i=0;i<n;++i){
			if(S[i]>max) max=S[i];
			for(int j=0;j<i+1;++j){
				if(S[i]-S[j]>max) max=S[i]-S[j];
			}
		}

		cout<<max<<endl;
	}

	return 0;
}

C++: #include <iostream>
int main(){
	int n, v[5000], m;
	while(std::cin >> n, n){
		for(int i=0;i<n;i++)std::cin >> v[i];

		m = v[0];
		for(int i=0;i<n;i++)
			for(int j=i,k=0;j<n;j++,k+=v[j])
				if(k>m)m=k;

		std::cout << m << '\n';
	}	
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>

using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int a[n];
		int max=0;
		for(int i=0;i<n;i++){
			a[i]=0;
			int input;
			cin>>input;
			for(int j=0;j<=i;j++){
				a[j]+=input;
				if(max<a[j])max=a[j];
			}
		}
		cout<<max<<endl;
	}
}

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

ll ara[10000];
int main()
{
    ll n;
    while(scanf("%lld", &n))
    {
        if(n==0) break;
        for(ll i=1; i<=n; i++){
            scanf("%lld", &ara[i]);
        }

        ll p=0;
        ll s=0;
        for(ll i=1; i<=n; i++){
            s = max(ara[i], s+ara[i]);
            p = max(p, s);
        }
        printf("%lld\n", p);
    }

    return 0;
}

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

C++: #include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main() {
	int n;
	while (cin >> n, n) {
		vi a(n + 1, 0);
		rep (i, n) cin >> a[i + 1];
		rep (i, n) a[i + 1] += a[i];
		int ans = -INF;
		rep (i, n) {
			range (j, i, n) {
				ans = max(ans, a[j + 1] - a[i]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {

		int Max = -100000;

		cin >> n;
		if( n == 0 ) break;

		a.push_back( 0 );

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		for( int i = 1; i < n; i++ ) {
		
			a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

			if ( a[i] > Max ) {
				Max = a[i];
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

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

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {

		int Max = -100000;

		cin >> n;
		if( n == 0 ) break;

????????????????????????a.push_back( 0 );

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		for( int i = 1; i < n - 1; i++ ) {
		
			a.at( i - 1 ) + a.at( i ) > a.at( i ) ? a.at( i ) = a.at( i - 1 ) + a.at( i ) : a.at( i ) = a.at( i );

			if ( a.at( i ) > Max ) {
				Max = a.at( i );
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

C++: #include<stdio.h>

int main()
{
	int n;
	while(scanf("%d",&n))
	{
		if(n==0){return 0;}
		
		int a[5000]={0},max=0;
		for(int x=0;x<n;x++)
		{
			scanf("%d",&a[x]);

			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>
#include <algorithm>
using namespace std;

int main(){
	int n, max1, max2, a[5001];

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

		for(int i=0 ; i<n ; i++){
			int sum = 0;
			for(int j=i ; j<n ; j++){
				sum += a[j];
				max1 = max( max1 , sum );
			}
		}
		cout << max1 << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		vector<int> a;
		for(int i=0;i<n;i++){
			int b;
			cin>>b;
			a.push_back(b);
		}
		vector<int> sum;
		for(int j=0;j<a.size();j++){
			int s=0;
			for(int k=j;k<a.size();k++){
				s += a[k];
				sum.push_back(s);
			}
		}
		sort(sum.begin(),sum.end());
		cout<<sum[sum.size()-1]<<endl;
	}
	return 0;
}

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

void main() {
	int n;

	while (cin >> n) {
		if (n == 0) break;
		vector<int> array(n);
		for (int i = 0; i < n; i++) {
			cin >> array.at(i);
		}

		long max = array.at(0);
		for (int j = 0; j < n; j++) {
			long total = 0;
			for (int k = 0; k < n - j; k++) {
				total += array.at(j + k);
				if (total > max) max = total;
			}
		}

		cout << max << endl;
	}
	return;
}