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 <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,0);
        vector<int>tempmax2(5010,0);
        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----------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>
//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;

//global-----------------------------------------------------------------------------------------------------------------------
LL a, b, n, ans = 0;
vector<LL> ar;
vector<LL> sum_ar;
//#define DEBUG
//function--------------------------------------------------------------------------------------------------------------------

int main() {
	while ( scanf( "%lld", &n ) && n ) {
		sum_ar.PB( 0 );
		ans = 0;
		rep( i, n ) {
			scanf( "%lld", &a );
			ar.PB( a );
			sum_ar.PB( sum_ar[ i ] + a );
		}
		rep( i, n ) {
			FOR( j, i, n + 1 ) {
#ifdef DEBUG
				debug(i)
				debug(j)
#endif
				ans = max( ans, sum_ar[ j ] - sum_ar[ i ] );
			}
		}
		printf( "%lld\n", ans );
		sum_ar = vector<LL>();
	}
	return 0;
}

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

int main(){
	int n;
	int a;
	int sum;
	int sum2;
	int max;
	cin >> n;
	while(n){
		cin >> sum;
		max = 0;
		for(int i=0;i<n-1;i++){
			cin >> sum2;
			if(sum < sum2){
				sum = sum2;
			}else{
				sum += sum2;
			}
			if(sum > max){
				max = sum;
			}
		}
		cout << max << endl;
		cin >> n;
	}
	return 0;
}

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

using namespace std;

bool testcase_ends() {
    size_t n;
    scanf("%zu", &n);

    if (!n) return 1;

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

    for (size_t i=1; i<n; ++i)
        a[i] += a[i-1];

    int min_e=*min_element(a.begin(), a.end());
    int max_e=*max_element(a.begin(), a.end());
    if (max_e < 0) {
        printf("%d\n", max_e);
    } else if (min_e < 0) {
        printf("%d\n", max_e-min_e);
    } else {
        printf("%d\n", max_e);
    }
    return 0;
}

int main() {
    int solved=0;
    while (!testcase_ends())
        ++solved;

    return !solved;
}

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

int main(){
	int n, m, a[5001], sum , max;

	while(1){
		max = 0;
		cin >> n;
		if(n==0) break;
		
		for(int i=0 ; i<n ; i++){
			cin >> a[i];
		}
		for(int i=0 ; i<n ; i++){
			sum = 0;
			for(int j=i ; j<n ; j++){
				sum += a[j];
				if(max<sum) max = sum;
			}
		}
		cout << max << endl;
	}
	return 0;
}

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

vector<int> num;

int main(void){
  while(true){
    int maximum = 0, n;
    cin >> n;
    if(!n)  break;
    num.clear();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < num.size(); i++){
      int sum = num[i];
      for(int j = i + 1; j < num.size(); j++){
        sum += num[j];
        if(sum > maximum) maximuma = sum;
      }
    }
    cout << maximum << endl;
  }
  return 0;
}

C++: #include<cstdio>
int main(){int n,i,j,s,m,a[5000];while(scanf("%d",&n)&&n){for(i=0;i<n;i++)scanf("%d",&a[i]);m=-500000001;for(i=0;i<n;i++,s=0)for(j=i;j<n;)if((s+=a[j++])>m)m=s;printf("%d\n",m);}}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int n, T[5001], dp[5001];
	while(cin >> n, n)
	{
		for(int i = 0; i < n; i++)
		{
			cin >> T[i];
		}

		memset(dp, -1, sizeof(dp));

		dp[0] = T[0];

		for(int i = 1; i < n; i++)
		{
			dp[i] = max(dp[i-1] + T[i], T[i]);
		}

		int res = -10000000;
		
		for(int i = 0; i < n; i++)
		{
			res = max(res, dp[i]);
		}

		cout << res << endl;
	}
}