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

C++: #include <iostream>
#include <algorithm>
#include <limits.h>
using namespace std;

int main(){
	int a[10000],n,s,m;
	while(cin>>n,n){
		m=INT_MIN;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=1;i<=n;i++){
			for(int j=0;j<n-i+1;j++){
				s=0;
				for(int k=0;k<i;k++){
					s+=a[j+k];
				}
				m=max(m,s);
			}
		}
		cout<<m<<endl;
	}
}

C++: #include<cstdio>
#define MAX(x,y) ((x>y)? x:y)

int n;
int a[5005];
long long int def;
long long int answer=-1000000000;

int main()
{
	while(true)
	{
		answer=-1000000000;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			def=0;
			for(int j=i;j<n;j++)
			{
				def+=a[j];
				answer=MAX(answer,def);
			}
		}
		printf("%lld\n",answer);
	}
	return 0;
}