Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

int main(){
	int n;
	while(scanf("%d",&n),n){
		int sum=0,ans=INT_MIN;
		rep(i,n){
			int t; scanf("%d",&t);
			sum += t;
			ans = max(ans,sum);
			if( sum<0 )sum=0;
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n, a[5000];
	for(;;){
		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] += a[i - 1];
		int min_sum = 0, ans = a[0];
		for(int i = 1; i < n; i++){
			min_sum = min(min_sum, a[i - 1]);
			ans = max(ans, a[i] - min_sum);
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  int n, x, max_;
  int dp[5000];
  while(1){
    cin >> n;
    if(!n) break;
    cin >> x;
    max_=x; dp[0]=x;
    for(int i=1; i<n; ++i){
      cin >> x;
      dp[i] = max(x, dp[i-1]+x);
      max_ = max(max_, dp[i]);
    }
    cout << max_ << endl;
  }
  return 0;
}

C++: /*
	0022:Maximum Sum Sequence
*/
#include	<iostream>
#include	<algorithm>

using namespace std;

int main(void) {
	while(1) {
		int n, ans = -10000;
		int array[5000];
		
		cin >> n;
		if(n == 0) { break; }
		
		for(int i = 0; i < n; i++) {
			cin >> array[i];
		}
		
		/*長さmlxの範囲を変えていく*/
		for(int mxl = 0; mxl < n; mxl++) {
			/*mlxの範囲内の最初の項（左端）をさす*/
			for(int i = 0; i < n - mxl; i++) {
				/*mlxの範囲の和を求める*/
				int sSum = 0;
				for(int j = 0; j <= mxl; j++) {
					sSum += array[i+j];
				}
				ans = max(ans, sSum);
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

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

int main()
{

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

	while( 1 ) {

		int Max = INT_MAX * -1;

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

		res.push_back( Max );
		a.clear();
	
	}

	for( vector< long int > :: iterator mIt = res.begin(); mIt != res.end(); ++mIt ) {
		cout << *mIt << endl;
	}

	return 0;

}

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

using namespace std;
int main(void)
{
    int n, a[1000];
    while (1) {
        cin >> n;
        if (n == 0)
            break;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        int goukei = 0, led = -10000000;
        for (int i = 1; i <= n; i++)
        {
            goukei = 0;
            for (int j = i; j <= n; j++)
            {
                goukei = goukei + a[j];
                led = max(goukei, led);
            }
        }
        cout << led << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int n ;
    cin >> n;
    while(n!=0){
      vector<int>a(n);
      vector<int>S(n+1);
      S.at(0) = 0;
      for(int i = 0;i < n;i++){
        cin >> a.at(i);
      }
      for(int i = 0;i < n;i++){
         S.at(i+1) = S.at(i) + a.at(i);
      }
      int ans = 0;
      for(int k = 0; k < n;k++){
      for(int i = 0; i < n-k  ;i++){
        if(S.at(n-k) - S.at(i) > ans){
          ans = S.at(n-k) - S.at(i);
      }
    }
  }
          cout << ans << endl;
          cin >> n;
        }
}

C++: #include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
if(n==0)
{
	break;
}
else
{
int a[n];
int r[5000];
for(int h=0;h<5000;h++)
{
	r[h]=-100001;
}
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
for(int j=0;j<n;j++)
{
	r[j]=a[j];
	if(a[j]<0)
	{}
	else
	{
		for(int k=j+1;k<n;k++)
		{
			if(a[k]<0)
			{
				break;
			}
			else
			{
				r[j]+=a[k];	
			}
		}
		
	}
}
int l=0;
	while(r[l]!=-100001)
	{
		if(r[l]>r[0])
		{
			r[0]=r[l];
			l++;
		}
	}
	cout<<r[0];
}
return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n;
	while (scanf("%d", &n), n) {
		int Max = INT_MIN, cnt = 0;
		rep(i, n) {
			int a; scanf("%d", &a);
			if (cnt < 0)cnt = a;
			else cnt += a;
			Max = max(Max, cnt);
		}
		printf("%d\n", Max);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int n;

constexpr long long minf = -100000 * 5000;

void solve(){
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    vector<ll> sum(n+10,0);    // sum[i] = a[0] + ... + a[i-1]
    for(int i=0;i<n;i++) sum[i+1] = sum[i] + a[i]; 

    ll ans = minf-10;

    rep(i,n) rep(j,n) if(i<j){
        // k = a[i] + ... + a[j]
        ll k = sum[j+1] - sum[i];
        ans = max(ans,k);
    }

    cout << ans << endl;
}

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

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    int ans = -1000000000;
    //るいせきわ
    vector<int> R(n + 1);
    R[0] = 0;
    
    for(int i = 0; i < n; i++) {
      R[i + 1] = R[i] + a[i];
    }

    for(int l = 0; l < n; l++) {
      for(int r = l; r < n; r++) {
        int temp = R[r + 1] - R[l];
        ans = max(ans, temp);
      }
    }

    cout << ans << endl;
  }
  return 0;
}