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 <iostream>
using namespace std;

int main(){
  int n;
  int a[5010];
  int s[5010];
  while(cin>>n && n){
    int mx=0;
    for( int i=1;i<=n;i++ ){
      cin >> a[i];
      mx = max(mx, a[i]);
    }
    for( int i=1;i<=n;i++ ){
      s[i] = a[i];
      for( int j=i+1;j<=n;j++ ){
	s[j] = s[j-1] + a[j];
	mx = max(mx, s[j]);
      }
    }

    cout << mx << endl;
  }
  return 0;
}

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

using namespace std;

int main() {

	int n;
	while (cin >> n, n != 0) {
		vector<int> data(n);
		for (int& temp : data) {
			cin >> temp;
		}

		int sum_max = numeric_limits<int>::min();
		for (auto it1 = data.begin(); it1 != data.end(); ++it1) {
			int temp = numeric_limits<int>::min();
			auto it2 = it1;
			do {
				++it2;
				int sum = accumulate(it1, it2, 0);
				if (sum > temp) {
					temp = sum;
				}

				if (sum_max < temp) {
					sum_max = temp;
				}
			} while (it2 != data.end());
		}
		cout << sum_max << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000001

using namespace std;
#define ll long long
#define dbg if(0)



int main(){
    while(true){
        int n;
        ll ans= LLONG_MIN;
        cin>>n;
        if (n==0)break;

        ll rui[n+1];
        rui[0]=0;
        for(int i=1;i<=n;i++){
            cin >>rui[i];
            rui[i]+=rui[i-1];
            dbg cout <<rui[i]<<" ";
        }
        dbg cout <<endl;
        //次を見る
        //今までの最小値を更新したか？
        //したなら暫定解を確定しansと比較。最大値=最小値=発見した最小値にする
        //してなければ最大値の更新をする
        //見る場所が一番後ろまで行ったら終了。
//        rui[0]=min(rui[0],rui[1]);
//        ll nmin=rui[0],nmax=rui[0];
//        bool nmflag=false;
        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                ans=max(rui[j]-rui[i-1],ans);
            }
        }
 /*       for(int i=0;i<=n;i++){
            if (rui[i]<nmin){
                ans=max(nmax-nmin,ans);
                nm=max(rui[i]-nmin,nm);
                nmax=rui[i];
                nmin=rui[i];
            }else{
                if(rui[i]>nmax){
                    nmax=rui[i];
                    nmflag=true;
                }
            }
            dbg cout <<nmax<<" "<<nmin<<" "<<nm<<endl;
        }
        ans=max(nmax-nmin,ans);
        dbg cout << endl;
        if(nmflag)cout<<ans<<endl;
        else cout<<nm<<endl;*/
        cout <<ans<<endl;
    }

    return 0;
}

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

int main(){

    int n, k;
    int d[5555];
    while(cin >> n){
      
      memset(d, 0, sizeof(d));
      for(int i=1;i<=n;i++){
	cin >> k;
	d[i] = d[i-1]+k;
      }
      
      int ans = 0;  
      for(int i=0;i<=n;i++){
	for(int j=i;j<=n;j++){
	  ans = max(ans, d[j]-d[i]);
	}
      }
      
    cout << ans << endl;
    }
}

C++: #include <iostream>
int main(){
int a,b,c=1,d=0;
while(c=1){
	std::cin>>a;
	
	int z=-100000;

	if(a==0){
		return 0;
	}
	int aa[a];
	for(int t=1;t<=a;t++){
		std::cin>>b;
	
		aa[t]=b;
	}
    
	for(int s=1;s<=a;s++){
		
			for(int l=s;l<=a;l++){
				d=d+aa[l];
				if(z<d){
					z=d;
				}
			}d=0;
		
		
	}
	std::cout<<z<<std::endl;
	
}
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
int main() {
	long long n, a[5001], rui[5002] = { 0 }, ans[5002], cnt = 0;
	while (1) {
		cnt++;
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
			rui[i + 1] = rui[i] + a[i];
		}
		int max;
		max = -100001;
		for (int i = 1; i <= n; ++i) {
			for (int j = i+1; j <= n; ++j) {
				if (rui[j] - rui[i] > max) {
					max = rui[j] - rui[i];
				}
			}
		}
		ans[cnt] = max;
	}
	for (int i = 1; i < cnt; ++i) {
		cout << ans[i] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int n ;
    cin >> n;
    while(n!=0){
      vector<int>a(n);
      vector<int>S(n+1);
      S.at(0) = 0;
      for(int i = 0;i < n;i++){
        cin >> a.at(i);
      }
      for(int i = 0;i < n;i++){
         S.at(i+1) = S.at(i) + a.at(i);
      }
      int ans = 0;
      for(int k = 0; k < n;k++){
      for(int i = 0; i < n;i++){
        if(S.at(n-k) - S.at(i+1) > ans){
          ans = S.at(n-k) - S.at(i+1);
      }
    }
  }
          cout << ans << endl;
          cin >> n;
        }
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;

int main(){
	int N;
	int x;
	while(1){cin>>N;if(N==0) break;int index=0;
		ll ans = 0;
		vl sum(N+1);
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}

C++: #include <iostream>
#include <cmath>
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;
    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++: #include <cstdio>
#include <algorithm>

using namespace std;

int N,K[5001],T;

int main()
{
        scanf("%d",&N);
        if (N == 0) return 0;

        T = 0;
        K[0] = 0;

        for (int i=1;i<=N;i++){
                scanf("%d",K+i);
        }

        for (int i=1;i<=N;i++) {
                K[i] += K[i-1];
        }

        for (int i=0;i<=N;i++) {
                for (int j=i;j<=N;j++) {
                        T = max(T,K[j]-K[i]);
                }
        }

        printf("%d\n",T);

        main();
}