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>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n && n) {
        int a[n + 1]; rrep(i, 1, n + 1) cin >> a[i]; a[0] = 0;
        int dp[n + 1]; dp[0] = 0;
        rrep(i, 1, n + 1) dp[i] = max(dp[i - 1] + a[i], a[i]);
        int larger = -inf;
        rrep(i, 1, n + 1) larger = max(larger, dp[i]);
        cout << larger << endl;
    }
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	while(true){
		int N=in();
		if(!N) break;
		auto V=vecin(N);
		ll max_v = -(1LL<<60);
		ll sum=0;
		REP(i,N){
			sum += V[i];
			max_v = max(max_v,sum);
			if(sum<0) sum=0;
		}
		out(max_v);
	}
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long a[5001] = { 0 };
	long n;
	cin >> n;
	a[0] = 0;
	long maxv = -100000;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		a[i] = max(a[i], a[i] + a[i - 1]);
		maxv = max(maxv, a[i]);
	}
	cout << maxv << endl;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	while(1){
		int n;
		int a[5001];
		cin>>n;
		if(n==0)break;
		int b;
		a[0]=0;
		cin>>a[1];
		for(int i=2;i<=n;i++){
			cin>>b;
			a[i]=a[i-1]+b;
		}
		int ans=0;
		for(int i=1;i<=n;i++){
			for(int j=0;j<i;j++){
				ans=max(ans,a[i]-a[j]);
			}
		}
		cout<<ans<<endl;
	}
}

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

int main(){
  int n, num, a, maxx;
  int ans[N], ac;
  ac = 0;

  while(cin >> n){
    if(n==0){
      ans[ac] = 0;
      break;
    }

    num = maxx = 0;

    for(int i=0;i<n;i++){
      cin >> a;
      num += a;
      if(num<0) num = 0;
      maxx = max(maxx,num);
    }
    ans[ac] = maxx;
    ac++;
  }

  for(int i=0;ans[i]!=0;i++)
    cout << ans[i] << endl;

  return 0;
}

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

C++: #include<cstdio>

int main(){
	int n,max,sum,t;
	scanf("%d", &n);
	while(n){
		scanf("%d", &t);
		max = sum = t;
		if(sum < 0){
			sum = 0;
		}
		for(int i = 1; i < n; i++){
			scanf("%d", &t);
			sum += t;
			if(sum > max){
				max = sum;
			}
			if(sum < 0){
				sum = 0;
			}
		}
		printf("%d\n", max);
		scanf("%d", &n);
	}
	return 0;
}

C++: #include<cstdio>
int main()
{
    int n,a[5000];
    while(scanf("%d",&n),n)
    {
        for(int i=0;i<n;i++)scanf("%d",&a[i]);
        for(int i=0;i<n-1;i++)a[i+1]+=a[i];

        int ma=-100000000;

        for(int l=0;l<n;l++){
            for(int r=l;r<n;r++){
                int sum;
                if(l==0)sum=a[r];
                else sum=a[r]-a[l-1];
                if(ma<sum)ma=sum;
            }
        }

        printf("%d\n",ma);
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int n;
        cin>>n;if(!n)return 0;
        long long a[5000];
        for(int i=0;i<n;++i){
            cin>>a[i];
        }
        long long ans;
        long long buf;
        for(int i=0;i<n;++i){
            buf=0;
            for(int j=i;j<n;++j){
                buf+=a[j];
                if(buf>ans)ans=buf;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int a[5001];
int sum[5001];
main(){
  while(1){
    int res=0;
    scanf("%d",&n);
    if(n==0) break;
    int sm=0;
    for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
      sm+=a[i];
      sum[i]=sm;
    }
    for(int i=0;i<n;i++)
      for(int j=i;j<n;j++)
	res=max(res,sum[j]-sum[i-1]);
    printf("%d\n",res);
  }
}

C++: #include <iostream>

using namespace std;

int main() {
	int n, *a;
	int ans, add;
	while (1) {
		cin >> n;
		if (n == 0)
			break;
		a = new int[n];
		for (int i = 0; i < n; i++)
			cin >> a[i];
		ans = 0;
		for (int i = 0; i < n; i++) {
			add = a[i];
			ans = max(ans, add);
			for (int j = i + 1; j < n; j++) {
				add += a[j];
				ans = max(ans, add);
			}
		}
		cout << ans << endl;
		delete[] a;
	}
	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 = -INF;
    rep(i, n+1) rep(j, i) maxup(res, a[i] - a[j]);

    cout << res << endl;
  }

  return 0;
}