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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n && n)
	{

		vint v(n+1); v[0] = 0;
		rep(i, n)
			cin >> v[i+1];

		partial_sum(ALL(v), v.begin());

		int res = -1 << 30;

		rep(i, n) REP(j, i + 1, n + 1)
			chmax(res, v[j] - v[i]);

		cout << res << endl;
	}
}

C++: #include <stdio.h>
#include <limits.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#define swap(type, x, y) do{type temp = x; x = y; y = temp;}while(0);
using namespace std;
int main(void) {
    int num;
    
    while(1) {
        int i, j, value;
        long long int ans = INT_MIN;
        scanf("%d", &num);
        if(num == 0) break;
        long long int sum[num + 1];
        
        for(i = 0; i < num + 1; i++) {
            sum[i] = 0;
        }
        
        for(i = 0; i < num; i++) {
            scanf("%d", &value);
            sum[i + 1] += sum[i] + value;
        }
        for(i = 0; i < num + 1; i++) {
            for(j = i + 1; j < num + 1; j++) {
                long long int psum = sum[j] - sum[i];
                if(psum > ans) ans = psum;
            }
        }
        cout << ans << endl;
    }
    
    return(0);
}

C++: #include<stdio.h>
int main(){
    int a;
    while(1){
        scanf("%d",&a);
        if(a==0)return 0;
        int n[5000];
        for(int i=0;i<a;i++)scanf("%d",n+i);
        int dp[5000];
        dp[0]=n[0];
        int max=0;
        for(int i=1;i<a;i++){
            if(dp[i-1]>0)dp[i]=dp[i-1]+n[i];
            else dp[i]=n[i];
            if(max<dp[i])max=dp[i];
        }
        printf("%d\n",max);
    }
}

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

int main()
{

	int n, num;
	vector< long int > a;

	while( 1 ) {

		int Max = -1000001;

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

		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;

}
*/

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

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {
	
		cin >> n;
		if( n == 0 ) break;

		int Max = -100001;

		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] = max( a[i], a[i] + a[i - 1] );
			Max  = max( Max, a[i] );
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

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

using namespace std;

int main(void){
	int n;
	while(scanf("%d", &n) && n){
		
		int num[5001]={0};
		int total[5001]={0};
		int ans = 0;
		
		for(int i = 0; i < n; i++){
			scanf("%d", &num[i]);
		}
		
		for(int i = 0; i < n; i++){
			for(int j = i; j < n; j++){
				total[i] += num[j];
				ans = max(ans,total[i]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main() {
	int n;
	long max, sum, ans=-1000000;
	while (true) {
		cin >> n;
		if (n == 0) break;
		vector<int> array(n);
		for (int i = 0;i < n;i++) {
			cin >> array[i];
		}

		for (int j = 0;j < n - 1;j++) {
			max = array[j] + array[j + 1];
			sum = array[j];
			for (int i = j + 1;i < n;i++) {
				sum += array[i];
				if (sum > max) {
					max = sum;
				}
			}
			if (j == 0) {
				ans = max;
			}
			else if (max > ans) {
				ans = max;
			}
		}
		if (array[n - 1] > ans) {
			ans = array[n - 1];
		}


		cout << ans << endl;
	}

	return 0;
}

C++: #include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
using namespace std;

int gcd(long long int m,long long int n){
	while(m!=n){
		if(m>n){m=m-n;
		}
		else n=n-m;
	}
	return m;
}
int lmc(long long int m,long long int n){
return m*n/gcd(m,n);
}

int main(){
int n;
while (cin>>n,n!=0){
	int a[5000];
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	int temp=-100000;
	for (int i=1;i<=n;i++){
		for (int j=0;j<=n-i;j++){
			int sum=0;
			for (int k=0;k<i;k++){
				sum+=a[j+k];
			}
			if (temp<sum){
				temp=sum;
			}

		}

	}
	cout<<temp<<endl;
}

}

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

int main() {
    vector<int> v;
    int n, a, sum;
    while (cin >> n && n != 0) {
        v.clear();
        for (int i=0; i<n; ++i) {
            cin >> a;
            v.push_back(a);
        }

        int l = 0;
        sum = 0;
        for (int i=0; i<n; ++i) {
            sum += v[i];
            if (sum < 0) {
                sum = 0;
                l = i+1;
            }
        }

        int r = n-1;
        sum = 0;
        for (int i=n-1; i>=0; --i) {
            sum += v[i];
            if (sum < 0) {
                sum = 0;
                r = i-1;
            }
        }

        sum = 0;
        for (int i=l; i<=r; ++i) {
            sum += v[i];
        }

        cout << sum << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int main(void)
{
  int a[5010]={};
  int tr;
  int i,j;
  int n;
  int max;

  for(scanf("%d",&n);n;scanf("%d",&n))
    {
      for(i=0;i<5010;i++)a[i]=0;
      max=0x80000000;
      for(i=1;i<=n;i++)
        {
          scanf("%d",&tr);
          a[i]=a[i-1]+tr;
        }
      for(i=0;i<n;i++)
        for(j=i;j<=n;j++)
          {
            tr=a[j]-a[i];
            if(max<tr)
              max=tr;
          }
      printf("%d\n",max);
    }

}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MAX_N 5001
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, a[MAX_N], sum, MAX;

int main(){
	while (cin >> n&&n){
		MAX = -100000000;
		REP(i, n)cin >> a[i];
		for (int i = 0; i < n; i++){
			sum = a[i];
			MAX = max(MAX, sum);
			for (int j = i + 1; j < n; j++){
				sum += a[j];
				MAX = max(MAX, sum);
			}
		}
		cout << MAX << endl;
	}
}