Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n;
    while (cin >> n and n) {
        vector<Int> a(n);
        for (Int i = 0; i < (Int)n; i++) {
            cin >> a[i];
        }
        vector<Int> b(n + 1, -INF);
        b[0] = 0;
        for (Int i = 0; i < (Int)n; i++) {
            b[i + 1] = max(b[i] + a[i], a[i]);
        }
        Int res = -INF;
        for (Int i = 0; i < (Int)n; i++) {
            res = max(res, b[i + 1]);
        }
        print(res);
    }
    return 0;
}

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

using namespace std;

int main() {
    vector<int> cum;
    int n, sum, tmp;
    
    while(true) {
        cin >> n;
        if(n == 0) { break; }
        
        cum.resize(n+1);
        cum[0] = 0;
        sum = (-2147483647);
        
        for(int i = 1; i <= n; i++) {
            cin >> tmp;
            cum[i] = cum[i-1] + tmp;
        }

        for(int i = 0; i < n; i++) {
            for(int j = i+1; j <= n; j++) {
                sum = max(sum, cum[j] - cum[i]);
            }
        }
        cout << sum << endl;
    }
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

const int MAX_N = 5000;
int n;
int a[MAX_N+2];

int main()
{
  while((cin >> n) && n){
    rep(i, n) cin >> a[i+1];
    rep(i, n) a[i+2] += a[i+1];

    int res = 0;
    rep(i, n+1) rep(j, i) maxup(res, a[i] - a[j]);

    cout << res << endl;
  }

  return 0;
}

C++: #include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)

using namespace std;
typedef long long ll;


int main(){
    int n;
    while(1){
        cin>>n;
        if(n==0)break;
        int dp[5000][5000]={};
        int a[5000]={};

        rep(i,5000)rep(j,5000)dp[i][j]=-INF;
        
        rep(i,n){
            cin>>a[i];
        }
        rep(i,n) dp[i][i]=a[i];
        
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                dp[i][j]=dp[i][j-1]+a[j];
            }
        }
        int maxi=-INF;
        rep(i,n){
            rep(j,n){
                maxi=max(maxi,dp[i][j]);
            }
        }
        cout<<maxi<<endl;
        
    }
    return 0;
}

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


int main() {
    int n;
    std::cin >> n;
    while (n != 0) {
        std::vector vec(n+1, 0);
        int x;
        for (int i = 1; i <= n; ++i) {
            std::cin >> x;
            vec[i] = x;
        }
        std::vector<int> sum;
        sum.assign(n+1, 0);
        sum[1] = vec[1];
        for (int i = 1; i < n; i++) {
            sum[i+1] = sum[i] + vec[i+1];
        }
        int ans = -1000000000;
        for (int l = 1; l <= n; ++l) {
            for (int r = l; r <= n; ++r) {
                ans = std::max(ans, sum[r] - sum[l-1]);
            }
        }
        std::cout << ans << std::endl;
        std::cin >> n;
    }
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.mss", "r", stdin);
	string str = "";
	int n;

	while (1){
		getline (cin, str );
		stringstream ssn(str);
		ssn >> n;
		if (n == 0){
			break;
		} // end if
		vector <int> a(n, 0);
		int i,j;

		vector <int> sum (n, 0);

		for (i = 0; i < n; ++i){
			getline (cin, str );
			stringstream ss(str);
			ss >> a[i];
		} // end for
		for (i = 0; i < n; ++i){
			sum[i] = accumulate (a.begin(), a.begin() + i + 1, 0 );
//			cout << "sum[" << i << "]:" << sum[i] << endl;
		} // end for

		int maxn = INT_MIN;
		for (i = 0; i < n; ++i){
			for (j = i + 1; j < n; ++j){
				 maxn = max (maxn , sum[j] - sum[ i - 1 < 0 ? 0 : i - 1]);
			} // end for
		} // end for
		cout << maxn << endl;			

	} // end while

	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int main(void){
	ll ans[10000];
	ll N=0;
	while(true){
		int n;
		cin>>n;
		if(n==0)break;
		ll a[5000];
		rep(i,n){
			cin>>a[i];
		}
		ll max=LLONG_MIN;//?????????0????????????????????§????????£???
		ll current;
		rep(i,n){
			current=0;
			reg(j,i,n-1){
				current+=a[j];
				if(current>max)max=current;
			}
		}
		ans[N]=max;
		N++;
	}
	rep(i,N)cout<<ans[i]<<endl;
	return 0;
}