Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

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;
}

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

using std::cin;

int main()
{

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

        std::vector<int> line(n);
        for (auto i = 0; i < n; i++) {
            int in;
            cin >> in;
            line.push_back(in);
        }

        int max = -100000;
        for (auto i = 0; i < n; i++) {
            int sum_ij;
            int max_i;
            max_i = sum_ij = line.at(i);
            for (auto j = i + 1; j < n; j++) {
                sum_ij += line.at(j);
                if (sum_ij > max_i) {
                    max_i = sum_ij;
                }
            }
            if (max_i > max) {
                max = max_i;
            }
        }

        std::cout << max << std::endl;
    }

    return 0;
}

C++: #include<stdio.h>

int main(){
	int n,a[5000],i,j,k,wa,max;
	
	while(0<=scanf("%d",&n)){
		if(n==0)break;
		max=0;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				wa=0;
				for(k=i;k<=j;k++){
					wa+=a[k];
				}
				if(max<wa)max=wa;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}