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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	while ( true )
	{
		int n;cin>>n;
		if(n==0)
			break;
		vector<int> a(n);
		for ( int i=0; i<n; i++ )
			cin>>a[i];
		long long ans=0;
		for ( int i=0; i<n; i++ )
		{
			long long t=0;
			for ( int j=i; j<n; j++ )
				t += a[j],
				ans = max(t,ans);
		}
		cout<<ans<<endl;
	}
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
#include <fstream>
#include <array>
#include <utility>
#include <functional>
#include <stack>
#include <math.h>

using namespace std;
typedef long long Int;
#define REP(i , x) for(Int i = 0 ; i < x ; ++i)
typedef pair<int, int> P;


int main()
{
	int n;

	while (cin >> n,n){
		Int dp[10000];
		Int aa[10000];

		fill(aa, aa + 10000, 0);
		fill(dp, dp + 10000, 0);

		REP(i, n){
			cin >> aa[i];
		}

		Int max_i = -99999999;

		dp[0] = aa[0];

		max_i = max(max_i, dp[0]);

		for(int i = 1; i < n ; ++i){
			dp[i] = max(aa[i], dp[i - 1] + aa[i]);
			max_i = max(max_i, dp[i]);
		}

		cout << max_i << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n, sum[5001] = {};
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      int a;
      cin >> a;
      sum[i + 1] = sum[i] + a;
    }
    int ret = sum[1];
    for(int i = 0; i <= n; i++){
      for(int j = i + 1; j <= n; j++){
        ret = max( ret, sum[j] - sum[i]);
      }
    }
    cout << ret << endl;
  }
}

C++: //
//AOJ volume0 0022
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0022&lang=jp
//20170529
//640009E
//Yang Bo
//

#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    vector<int> a(n, 0); //?´??????¨
    vector<int> b(n, 0); //????????¨
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int k = n - 1;
    while (a[k] < 0)
      k--;
    b[k] = a[k];
    for (int i = k - 1; i > -1; i--) {
      if (a[i] < 0)
	continue;
      else {
	int j = i + 1;
	int s = 0; //?????????????????????????????¨
	while (a[j] < 0) {
	  s += a[j];
	  j++;
	}
	//cout << "s = " << s << " " << "i = " << i << " " << "j = " << j << endl;
	if (s + b[j] >= 0)
	  b[i] += s + b[j] + a[i];
	else // if (a[i] > s + b[j])
	  b[i] += a[i];
	//cout << "b[" << i << "]= " << b[i] << endl;
      }
    }
    /*
    for (int i = 0; i < n; i++)
      cout << "b[" << i << "]= " << b[i] << endl;
    */
    int max = b[0];
    for (int i = 1; i < n; i++)
      if (max < b[i])
	max = b[i];
    if (max < 1) {
      int minus = a[0];
      for (int i = 1; i < n; i++)
	if (minus < a[i])
	  minus = a[i];
      max = minus;
    }
    cout << max << endl;
  }
}

/*
??????????????????????????£???????????§??????????????????wrong answer???????????§??????
????????§?????£???????????¨???????????§?????????????????????????????????
?????????????????§????????§????±?????????????(??????b?????\????????????????????????)?????¨????????°?????????????±?????????¨????????¢?????´?????????????????£???????????????
????????£???????¬??????????????¨?????????¨?¨????????????§???????????????
*/

C++: #include <iostream>
#include <algorithm>
const int MAX_N = 5000;
using namespace std;

int a[MAX_N];

int main(void) {
  int n;
  
  while (cin >> n) {
    if (n == 0) break;
    long long max_num = -500000000;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n-i; j++) {
	long long tmp = 0;
	for (int k = i; k <= j; k++) {
	  tmp += a[k];
	}
	max_num = max(max_num, tmp);	
      }
    }

    cout << max_num << endl;
  }

  return 0;
}

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

int a[5000] = {0};
int S[5000] = {0};

int main() {
  int n;
  while(cin >> n) {
  if(n == 0) break;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }

  S[0] = a[0];
  for(int i = 1; i < n; i++) {
    S[i] += S[i-1] + a[i];
  }
  

  int maxsum = 0;
  int sum = 0;
  for(int i = 1; i <= n-1; i++){
    for(int j = i + 1; j <= n;j++) {
      sum = S[j] - S[i];
      if(sum > maxsum)
	maxsum = sum;
      sum = 0;
    }
  }
  cout << maxsum << endl;
  }
}

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

int main(void) {
  int n, a[5001];
  long long int sum, mx;
  
  while(cin>>n && n) {
    for(int i = 0; i < n; i++) cin >> a[i];

    mx=0; sum=0;
    for(int i = 0; i < n; i++) {
      sum=0;
      for(int j = i; j < n; j++) {
	sum+=a[j];
	mx=max(mx, sum);
      }
    }
    cout<<mx<<endl;
  }

  return 0;
}

C++: /*
 * AOJ-Volume0-0022
 */
#include <iostream>
#include <vector>

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 <bits/stdc++.h>
using namespace std;

int a[5001];

int main() {
  int num;
  while( cin >> num, num ) {
    int maxn = 0;
    for ( int i = 0; i < num; i++ ) cin >> a[i];
    for ( int i = 0; i < num; i++ ) {
      int sum = 0;
      for ( int j = i; j < num; j++ ) {
	sum += a[j];
	maxn = max(maxn,sum);
      }
    }
    cout << maxn << endl;
  }
  return 0;
}

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

const int N = 100;
int rsum[N+1][N];
int in[N][N];

void precalc(int n){
  for(int j=0;j<n;j++){
    rsum[0][j] = 0;
    for(int i=0;i<n;i++){
      rsum[i+1][j] = rsum[i][j] + in[i][j];
    }
  }
}

int maximumSum1D(int n,int *a){
  int ret = a[0],cur = a[0];
  for(int i=1;i<n;i++){
    if (cur < 0){
      cur = a[i];
    }else {
      cur = cur + a[i];
    }
    ret = max(ret,cur);
  }
  return ret;
}

int solve(int n){
  int ret = 0;
  int a[n];
  for(int i=0;i<n;i++){
    for(int k=i;k<n;k++){
      for(int j=0;j<n;j++){
	a[j] = rsum[k+1][j] - rsum[i][j];
      }
      ret = max(ret,maximumSum1D(n,a));
    }
  }
  return ret;
}

main(){
  int n;
  while(cin>>n && n){
    int a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    cout << maximumSum1D(n,a) << endl;
  }
}

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

int a[5001];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	a[0] = 0;
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
		a[i] += a[i - 1];
	}

	int m = -100000;
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j < i; ++j){
			m = max(m, a[i] - a[j]);
		}
	}

	std::cout << m << std::endl;

	return 0;
}