Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var infty = 100000 * 2
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	scanner.Scan()
	return strconv.Atoi(scanner.Text())
}

func findMaximumSubarray(arr []int) int {
	currentMaxSum, maxSumContainsTail := -infty, -infty

	for j := range arr {
		if arr[j] > maxSumContainsTail+arr[j] {
			maxSumContainsTail = arr[j]
		} else {
			maxSumContainsTail += arr[j]
		}
		if currentMaxSum < maxSumContainsTail {
			currentMaxSum = maxSumContainsTail
		}

		// fmt.Println(arr[j], currentMaxSum, maxSumContainsTail)
	}
	return currentMaxSum
}

func main() {
	scanner.Split(bufio.ScanWords)
	for {
		size, _ := nextInt()
		if size == 0 {
			break
		}

		arr := make([]int, size)
		for i := range arr {
			n, _ := nextInt()
			arr[i] = n
		}

		maximumSum := findMaximumSubarray(arr)
		fmt.Println(maximumSum)
	}
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        int data[10000]={};
        rep(i,n) cin>>data[i];
    
    
        int maxi=-999999999;
        int dp[500][500]={};
        rep(i,n){
            for(int j=i;j<n+1;j++){
                if(i-1>=0){
                    dp[i][j]=dp[i][j-1]+data[j-1];
                    maxi=max(maxi,dp[i][j]);
                }
            }
        }
        cout<<maxi<<endl;
    }
    return 0;
}

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

using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		long long int a[5000], sum = 0, hold = 0;
		for(int i = 0;i < n;i++){
			cin >> a[i];
		}
		hold = a[0];
		for(int i = 0;i < n;i++){
			sum += a[i];
			for(int j = i+1;j < n;j++){
				sum += a[j];
				if(hold < sum){
					hold = sum;
				}
			}
			sum = 0;
		}
		cout << hold << endl;

	}
	
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int z=-1,n,i,j[255],o,maxo=-100000,s[5000]={0};
	scanf("%d",&n);
	while(n!=0){
		o=0;
		z++;
		for(i=0;i<n;i++){
			scanf("%d",&s[i]);
		}
		for(i=1;i<n;i++){
			if(s[i]<s[i-1]+s[i]){
				s[i]=s[i-1]+s[i];
			}

		}
		for(i=0;i<n;i++){
			maxo=max(maxo,s[i]);
		}
		j[z]=maxo;
		maxo=-100000;
		scanf("%d",&n);
	}
	for(i=0;i<=z;i++){
		printf("%d\n",j[i]);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> Pi;

const int INF=100000000;
const long long int INF_=1000000000000000000;

int main(){
	int N;
	while(cin >> N&&N){
		vector<int> A(N+1);
		REP(i,1,N+1) cin >> A[i];
		vector<int> s(N+1);
		REP(i,1,N+1) s[i]=s[i-1]+A[i];
		lli ans=-INF_;
		REP(i,0,N+1) REP(j,i+1,N+1) if(ans<s[j]-s[i]) ans=s[j]-s[i];
		cout << ans << endl;
	}
	return 0;
}

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


int main(){
  int n;
  int c[12345], b[12345];
  for(;;){
    cin >> n;
    if(n==0) break;
    for(int i=0; i<n; i++){
      cin >> c[i];
    }
    b[0] = 0;
    for(int i=0; i<n; i++){
      b[i+1] = b[i]+c[i];
    }
    
    int mx = -123456;
    for(int i=0; i<n+1; i++){
      for(int j=i+1; j<n+1; j++){
        if(mx < b[j]-b[i]){
          mx = b[j]-b[i];
        }
        
      }
    }
    cout << mx << endl;
  }
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  while(n!=0){
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a.at(i);

    vector<int> s(n+1);
    s.at(0) = 0;
    for(int i=1;i<=n;i++) s.at(i) = s.at(i-1)+a.at(i-1);

    int ans=0;
    for(int i=1;i<=n;i++){
      for(int j=0;j<i;j++){
        ans = max(s.at(i)-s.at(j),ans);
      }
    }

    cout << ans << endl;

    cin >> n;
  }
}

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

using namespace std;

int main(int argc, char *argv[]) {
  vector<int> maxsums, a;
  int n, tmp;

  a.reserve(5000);
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    for (int i = 0; i < n; i++) {
      tmp = a[i];
      for (int j = i + 1; j < n; j++) {
        tmp += a[j];
        if (tmp > a[i])
          a[i] = tmp;
      }
    }

    int max = a[0];
    for (int i = 0; i < n; i++)
      if (max < a[i])
        max = a[i];
    maxsums.push_back(max);
  }

  for (int i = 0; i < maxsums.size(); i++)
    cout << maxsums[i] << endl;
  return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int n,a[5000],s,ans;
	
	while(1){
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> a[i] ;
		}
			if(n==0){
				break;
			}
		ans=0;
		for(int i=1;i<=n;i++){
			for(int j=0;j<=n-i;j++){
				s=0;
				if((a[j]<=0)||(a[j+i-1]<=0)){
					goto A;
				}
				for(int k=j;k<j+i;k++){
					s+=a[k];
				}
				if(ans<s){
					ans=s;
				}
					A:;
			}
		}
		if(s==0){
			for(int i=1;i<n;i++){
				for(int j=0;j<n-i;j++){
					if(a[j]<a[j+1]){
						s=a[j]; a[j]=a[j+1]; a[j+1]=s;
					}
				}
			}
			ans=a[0];
		}
	cout << ans << "\n" ;
	}
return 0;
}

C++: /*
 * AOJ-Volume0-0022
 */
#include <iostream>
#include <limits.h>
#include <vector>
#include <cstdio>

using namespace std;

typedef long long ll;

/*
 * Find maximum sum.
 *   array: number list
 */
int findMaximumSum(vector<int> &array){
  int sumValue = array[0];
  int maxValue = INT_MIN;
  int length = array.size();

  for(int i = 1; i < length; i++){
    int value = array[i];

    if(sumValue < 0){
      sumValue = value;
    }else{
      sumValue += value;
    }

    if(maxValue < sumValue){
      maxValue = sumValue;
    }
  }

  return maxValue;
}

void solve(int n){
  vector<int> a(n);

  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  printf("%d\n", findMaximumSum(a));
}

int main(){
  int n;

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

    solve(n);
  }

  return 0;
}

C++: //まともに使い方を理解していないくせにincludeしまくる人間のクズ
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
//#include <set>
#include <map>
#include <bitset>
#include <iostream>


//using namespace stdしないと表記がめんどくさいからね、仕方ないね
using namespace std;

//可読性を上げるためのdefineが仇となる典型的パターン
#define rep(i,n) for(int i = 0; i < x; i++)

//ローカル変数とグローバル変数は使い分けよう！
stack<short> x, y;
long long int ans, n, array[5000];

//関数って楽しいよね！（魔王スマイル）

void solve(long long int sum, short i){
    if(ans < sum) ans = sum;
    if(i == n) return;
    solve(sum + array[i], i + 1);
    solve(0, i + 1);
}

int main(){
    while(true){
        scanf("%lld", &n);
        if(n == 0) return 0;
        ans = 0;
        rep(i,n) scanf("%lld", &array[i]);
        solve(0, 0);
        printf("%lld\n", ans);
    }
}