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++: //#define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    while(true) {
        int n;
        vi v;
        cin >> n;
        if(n==0) break;

        while(n--) {
            int tmp;
            cin >> tmp;
            v.push_back(tmp);
        }
        vi w(v);
        rep(i, v.size()) v[i] = max(v[i-1] + v[i], v[i]);
        P(*max_element(ALL(v)));
    }
    return 0;
}

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

int main(){
  int n;
  int list[5000];

  while( (cin>>n) != 0){
    int temp=0;
    int max=0;
    for(int i=0; i<n; i++){
      cin >> list[i];
    }
    for(int i=0; i<n; i++){
      temp += list[i];
      if( temp<=0 ){
        temp=0;
      }
      if(max<temp){
        max=temp;
      }
    }

    cout << "output: " << max << endl;
  }

  return 0;
}

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


int main(){
	while (true)
	{
		int n, a[5001] = {};
		long long int ans = -100000, sum;
		cin >> n;
		if (n == 0) { break; }
		for(int i = 0;i<n;i++){
			cin >> a[i];
		}
		for(int i = 0;i<n;i++){
			sum = 0;
			for(int j = i;j<n;j++){
				sum += a[j];
				if(sum > ans){
					ans = sum;
				}
			}
		}

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

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

using namespace std;

#define FOR(a) for(int i = 0; i < a; i++)
#define FORR(a, b) for(int i = a; i < b; i++)

int main(void){
	int Max, Num = -1, In, N = 0;
	while (Num != 0){
		vector<int>	Dat;
		Max = -100000;
		cin >> Num;
		Dat.push_back(-100000);
		FOR(Num){
			cin >> In;
			Dat.push_back(In);
		}
		FORR(1, Num + 1){
			Dat[i] = max(Dat[i], Dat[i - 1] + Dat[i]);
			Max = max(Max, Dat[i]);
		}
		cout << Max << endl;
	}
	return 0;
}

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

#define INF -100000000

int main(){
  

  int dataSets;

  while(true){
    vector<int> a;
    cin >> dataSets;
    if(dataSets==0){break;}
    for(int i=0;i<dataSets;i++){
      int tmpa;
      cin >> tmpa;
      a.push_back(tmpa);

    }

    int tmax=INF;
    // i?????§????????§?????????????????????
    vector<int> tmpMax(dataSets + 1,0);
    tmpMax[0] = 0;
    for(int i=1;i<dataSets+1;i++){
      tmpMax[i] += tmpMax[i-1] + a[i-1];
    }

    for(int i=0;i<dataSets;i++){
      for(int j=i+1;j<dataSets+1;j++){
	tmax = max(tmax, tmpMax[j]-tmpMax[i]);
      }
    }
    
    // for(int i=0;i<dataSets+1;i++){
      // for(int j=i;j<dataSets;j++){
	// tmax = max(tmax, tmpMax[j+1] - tmpMax[i]);
      // }
    // }
    
    cout << tmax << endl;
    
  }

  return 0;

}

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

int main() {
	int n;
	while (true) {
		cin >> n;
		if (n == 0)break;
		int* nums = new int[n];
		for (int i = 0; i < n; i++) {
			cin >> nums[i];
		}
		int max = -100001; 
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n - i; j++) {
				int tmp = 0;
				for (int k = i; k <= j; k++) {
					tmp += nums[k];
				}
				if (max < tmp)max = tmp;
			}
		}
		cout << max << endl;
	}
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> vec;
#define INF (1<<20)

int main(){
	int n;
	while( cin >> n, n ){
		vec data(n);
		for( int i = 0; i < n; i++ ){
			cin >> data[i];
		}
		int ans = -INF;
		vector<vec> dp(n, vec(n));
		for( int i = 0; i < n; i++ ){
			for( int j = i; j < n; j++ ){
				if( i == 0 ){
					if( j == 0 ) dp[0][0] = data[0];
					else dp[0][j] = dp[0][j-1] + data[j];
					ans = max(ans, dp[i][j]);
				}else{
					//if( i <= j ){
						dp[i][j] = dp[i-1][j] - data[i-1];
						ans = max(ans, dp[i][j]);
					//}
				}
			}
		}
		/*for( int i = 0; i < n; i++ ){
			for( int j = 0; j < n; j++ ){
				printf("%4d", dp[i][j]);
			}
			cout << endl;
		}
		*/
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

#define vcitr vector<int>::iterator
#define vcsitr vector<string>::iterator
#define mapcitr map<char, int>::iterator
#define mapsitr map<string, int>::iterator

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }

int a[5050];

int main() {
	int n;
	
	while (cin>>n) {
		if (n==0) break;
		for (int i=0; i<n; i++) cin >> a[i];
		
		int ans = -iINF;
		for (int i=0; i<n; i++) {
			int sum = 0;
			for (int j=i; j<n; j++) {
				sum += a[j];
				ans = max(ans, sum);
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}