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

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int a[5001];
int sum[5001];
main(){
  while(1){
    int res=0;
    scanf("%d",&n);
    if(n==0) break;
    int sm=0;
    for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
      sm+=a[i];
      sum[i]=sm;
    }
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	int s=i-1<0?0:sum[i-1];
	res=max(res,sum[j]-s);
      }
    }
    printf("%d\n",res);
  }
}

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

using namespace std;

int main(){

  int n;


  while(cin >> n){
    if(n == 0) break;
    vector<int> V;
    int status = 1;
    int in;
    int sum = 0;
    for(int i = 0; i < n; i++){

      cin >> in;
      
      if(in < 0 && status == 1){
	status = -1;
	V.push_back(sum);
	sum = 0;
      }else if(in > 0 && status == -1){
	status = 1;
	V.push_back(sum);
	sum = 0;
      }
      
      sum += in;
    }

    V.push_back(sum);

    int max = 0;
    
    for(int i = 0; i < V.size(); i++){
      sum = 0;
      for(int j = i; j < V.size(); j++){
	sum += V[j];
	if(max < sum) max = sum;
      }
    }
    
    cout << max << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;

int main()
{
	int n;

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

		int sum = 0, input, maxer = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> input;
			sum += input;

			if (sum < 0)
				sum = 0;
			maxer = max(sum, maxer);
		}

		cout <<  maxer << endl;
	}


	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int i;
	long max;
	long total;
	int a[5010];
	int n;
	
	while (scanf("%d", &n), n != 0){
		max = 0;
		total = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
			total += a[i];
			if (max < total){
				max = total;
			}
			if (total < 0){
				total = 0;
			}
		}
		printf("%d\n", max);
	}
	return (0);
}

C++: #include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
int main() {
  int n, input;
  vector<int> input_v;
  vector<int> part_v;
  int max_num = 0;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    input_v.clear();
    while(n--) {
      cin >> input;
      input_v.push_back(input);
    }
    max_num = 0;
    for (int i = 0; i < input_v.size(); ++i) {
      for (int len = 2; len <= input_v.size() - i; ++len) {
        part_v.clear();
        for (int m = 0; m < len && i + m < input_v.size(); ++m) {
          part_v.push_back(input_v[i + m]);
        }
        max_num = max(accumulate(part_v.begin(), part_v.end(), 0), max_num);
      }
    }
    cout << max_num << endl;
  }
  return 0;
}