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 <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

// 最大部分列を求める
long long maximum_subarray(vector<int> &a) {
    long long res = numeric_limits<long long>::min();
    long long s = 0;
    for (int i = 0; i < (int)a.size(); ++i) {
        s = max(s, 0LL) + a[i];
        res = max(res, s);
    }
    return res;
}

void _main() {
    int n;
    while (cin >> n, n) {
        vector<int> a(n);
        cin >> a;
        cout << maximum_subarray(a) << endl;
    }
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    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 = -100001;
		cin >> Num;
		Dat.push_back(-100001);
		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>
using namespace std;

int main(){
	bool flag[5000] = {false};
	int n, in[5000], ans, tmp = 0;
	
	while(true){
		cin >> n;
		if(n == 0)
			break;

		for(int i = 0; i < n; ++i){
			cin >> in[i];
			if(in[i] > 0)
				flag[i] = true;
		}//input

		for(int i = 0; i < n; ++i){
			for(int j = i + 1; j < n; ++j){
				if(flag[i] && flag[j]){
					for(int k = i; k <= j; ++k)
						tmp += in[k];
					if(tmp > ans){
						ans = tmp; 
						tmp = 0;
					}	
					else
						tmp = 0;
				}
			}
		}
		
		cout << ans << endl;//output
		
		ans = 0;
		for(int i = 0; i < n; ++i)
			flag[i] = false;//intialize
	
	}
	
	return 0;
}

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

using namespace std;

int intervalSum(int cs[], int a, int b);

int main(void) {
	while(1) {
		int n, ans = -10000;
		int array[5000], cumsum[5000] = { 0 };
		
		cin >> n;
		if(n == 0) { break; }
		
		for(int i = 0; i < n; i++) {
			cin >> array[i];
			if(i == 0) { cumsum[i] = array[i]; }
			else { cumsum[i] = array[i] + cumsum[i-1]; }
		}
		
		for(int i = 0; i < n; i++) {
			for(int j = i; j < n; j++) {
				int fl;
				if(i == j) {
					fl = array[i];
				} else if(i == 0) {
					fl = cumsum[j];
				} else {
					fl = intervalSum(cumsum, i, j);
				}
				ans = max(ans, fl);
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

int intervalSum(int cs[], int a, int b) {
	return cs[b] - cs[a-1];
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        vector<int> a(n);
        for(int i=0;i<n;i++)cin>>a[i];
        int ans=-1000000;
        for(int i=0;i<n;i++){
            int sum=0;
            for(int j=i;j<n;j++){
                sum+=a[j];
                if(ans<sum)ans=sum;
            }
        }
        cout<<ans<<endl;
    }
}

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

int main(){
  int n, num, a, maxx;

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

    num = 0;

    for(int i=0;i<n;i++){
      cin >> a;
      num += a;
      if(i == 0)
        max = a;
      if(num<0) num = 0;
      maxx = max(maxx,num);
    }
    cout << maxx << endl;
  }

  return 0;
}

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

int main(){
	const int nmax = 5001;
	int n;
	int nums[nmax];
	while(cin >> n){
		if(n == 0) break;
		int a;
		for(int i = 1;i <= n; i++){
			cin >> a;
			nums[i] = a;
		}
		int total_max = -2147483648;
		for(int i = 1; i <= n; i++){
			int total = 0;
			for(int j = i; j <= n; j++){
				total += nums[j];
				total_max = max(total_max, total);
			}
		}
		cout << total_max << endl;
	}
	return 0;
}