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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    vi a(n);
    rep(i, n) cin >> a[i];
    int m = -INF;
    rep(i, n) {
      int c = 0;
      loop(j, i, n) {
        c += a[j];
        cmax(m, c);
      }
    }
    cout << m << endl;
  }
}

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

int maximum_sum_seq(vector<int> seq,int n) {
  int max_sum = seq[0];
  int cur = seq[0];
  for(int i=0;i<n;i++) {
    cur = seq[i];
    for(int j=i+1;j<n;j++) {
      cur += seq[j];
      max_sum = max(max_sum,cur);
    }
  }
  return max_sum;
}

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

  int n;
  while(cin >> n) {
    if(n == 0) break;
    vector<int> seq(n);
    for(int i=0;i<n;i++) {
      cin >> seq[i];
    }
    cout << maximum_sum_seq(seq,n) << endl;
  }
}

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

int main()
{
   int n;
   int a;
   int maxsum=0;
   cin>>n;
   for(int i=0;i<n;++i){
      cin>>a;
      if(a>0){
         maxsum+=a[i];
      }
   cout<<maxsum<<endl;
}

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

int main(){

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

C++: #include <stdio.h>

int main()
{
	int n, x, p;
	
	while(scanf("%d", &n) != 0){
		if (n == 0) break;
		
		int a[n];

		for(int i = 0; i < n; i++){
			scanf("%d", &a[i]);
		}

		x = a[0];

		for(int i = 1; i <= n; i++){
			for(int j = 0; j < n-i+1; j++){
				p = 0;

				for(int k = 0; k < i; k++){
					p += a[j+k];
				}

				if(x < p) x = p;
			}
		}

		printf("%d\n", x);
	}

	return 0;
}

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

int main() {
    int n;
    while(cin >> n) {
        if(n == 0) break;
        n++;
        int a[5010]; a[0] = 0;
        for(int i=1; i<n; i++) {
            cin >> a[i];
            a[i] += a[i-1];
        }

        int ret = 0;
        for(int i=0; i<n; i++) {
            for(int j=i; j<n; j++) {
                ret = max(a[j] - a[i], ret);
            }
        }

        cout << ret << endl;
    }
    return 0;
}

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

C++: #include<stdio.h>
main(){
	int i,j,n,a[5000];
	
	int sum = 0,max = 0,ans = 0;
	
	
	while(1){
		
		max = 0;
	
		scanf("%d",&n);
		
		if(n==0) break;
		
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		
		for(i = n - 1; (i >= 0)&&(a[i] <= 0); i--);
		
		n = i;
		
		for(i = 0; (i <= n)&&(a[i] <= 0); i++);

		
		for( ;i <= n; i++){
			
			sum = 0;
			
			for(j = i; j <= n; j++) sum += a[j];
			
			max = sum;
			
			for(j = n; j >= i; j--){
				
				sum -= a[j];
				
				if(sum > max) max = sum;
				
			}
			
			if(max > ans ) ans = max;
		}

		printf("%d\n",ans);
		
		
		sum = 0;
		max = 0;
		ans = 0;
		
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int answer[5010] = {0};
    int l = 0;
    while(cin >> number,number)
    {
        int a[5010] = {0};
        vector<int>tempmax(5010.500);
        vector<int>tempmax2(5010);
        REP(i,number)
        cin >> a[i];
        for(int i = number;i>=0;i--)
            for(int j = 0; j<i;j++)
            {
                tempmax[i] +=a[j];
            }
        for(int k = 0;k<number;k++)
            for(int m = k;m<number;m++)
            {
                if(k == m)
                    tempmax2[k] = a[k];
                else if(tempmax2[k]+a[m] >= tempmax2[k])
                    tempmax2[k]+= a[m];
                else
                    break;
            }
        sort(tempmax.begin(),tempmax.end(),greater<int>());
        sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        if(tempmax[0]>tempmax2[0])
            answer[l] = tempmax[0];
        else
            answer[l] = tempmax2[0];
        l++;
    }
    REP(i,l)
    cout << answer[i] << endl;
    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;
	vector<int>	Dat;
	while (Num != 0){
		Max = -100000;
		cin >> Num;
		Dat.push_back(0);
		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()
{
	int n, a[5000], i, j, k, l, sum, max;

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

		for (i = 0; i < n; i++)
			cin >> a[i];

		max = -2147483647;
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n - i; j++)
			{
				for (k = 0; k < n - i; k++)
				{
					sum = 0;
					for (l = k; l <= i; l++)
						sum += a[l];
					if (sum > max) max = sum;
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}