Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var infty = 100000 * 2
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	scanner.Scan()
	return strconv.Atoi(scanner.Text())
}

func findMaximumSubarray(arr []int) int {
	currentMaxSum, maxSumContainsTail := -infty, -infty

	for j := range arr {
		if arr[j] > maxSumContainsTail+arr[j] {
			maxSumContainsTail = arr[j]
		} else {
			maxSumContainsTail += arr[j]
		}
		if currentMaxSum < maxSumContainsTail {
			currentMaxSum = maxSumContainsTail
		}

		// fmt.Println(arr[j], currentMaxSum, maxSumContainsTail)
	}
	return currentMaxSum
}

func main() {
	scanner.Split(bufio.ScanWords)
	for {
		size, _ := nextInt()
		if size == 0 {
			break
		}

		arr := make([]int, size)
		for i := range arr {
			n, _ := nextInt()
			arr[i] = n
		}

		maximumSum := findMaximumSubarray(arr)
		fmt.Println(maximumSum)
	}
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

  template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
    if(n == 0) break;
    vector<int> a(n+1,0);
    int ans =0,res= 0;
    rep(i,n){
      cin >> a[i];
      ans +=a[i];
    }
    rep(i,n){
      deque<int> kt(n+1,0);
      for(int j = i;j<n;++j){
        kt[j+1] += kt[j]+a[j];
      }
      ans = max(ans,*max_element(kt.begin()+i+1,kt.begin()+n));
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

static const int INF=1<<29;

bool testcase_ends() {
    int n;
    scanf("%d", &n);

    if (!n) return 1;

    int res=-INF, seq=-INF;
    for (int i=0; i<n; ++i) {
        int a;
        scanf("%d", &a);

        seq = max(seq+a, a);
        res = max(res, seq);
    }

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

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

    return !solved;
}

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

C++: #include<iostream>
#include<cstring>
#define N 5001
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
    int n;
    while(cin >> n &&n)
    {
        if(n==0)break;
        long int s[N];
        //memset(s,0,sizeof(int)*N);
        int t;
        long int max = 0;
        long int min = 0;
        /*cin >> t;
        s[0]=t;max = t;min=t;*/
        s[0] = 0;
        for(int i=0;i<n;i++){
            cin >>t;
            s[i+1] = s[i]+t;
            if(max<s[i+1])max = s[i+1];
            if(min>s[i+1])min = s[i+1];
        }
        if(n==1) {cout << max << endl; continue;}
        cout << max - min << endl;

    }

    return 0;
}

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

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

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

int main() {
  int n;

  while(cin >> n, n) {
    VI a(n);
    REP(i, n) cin >> a[i];

    int ans = 0;
    REP(i, n) {
      int sum = 0;
      FOR(j, i, n) {
	sum += a[j];
	ans = max(sum, ans);
      }
    }

    cout << ans << endl;
  }
}

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

int a[5000] = {0};
int S[5001] = {0};

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

  for(int i = 1; i <= n; i++) {
    S[i] = S[i-1] + a[i-1];
  }
  

  int maxsum = 0;
  int sum = 0;
  for(int i = 0; i <= n-1; i++){
    for(int j = i + 1; j <= n;j++) {
      sum = S[j] - S[i];
      if(sum > maxsum)
	maxsum = sum;
      sum = 0;
    }
  }
  cout << maxsum << endl;
  }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	while(1){
		long long n;
		long long a[5001];
		cin>>n;
		if(n==0)break;
		long long b;
		a[0]=0;
		cin>>a[1];
		for(int i=2;i<=n;i++){
			cin>>b;
			a[i]=a[i-1]+b;
		}
		long long 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>
using namespace std;

int main()
{
	int n;
	while(cin>>n){
		if(n==0) break;
		int a[n], S[n], sum=0;
		for(int i=0;i<n;++i){
			cin>>a[i];
			sum+=a[i];
			S[i]=sum;
		}

		long max=-99999999;
		for(int i=0;i<n;++i){
			if(S[i]>max) max=S[i];
			for(int j=0;j<n-1;++j){
				if(S[i]-S[j]>max) max=S[i]-S[j];
			}
		}

		cout<<max<<endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
while (1){
long n,dset[5000],temp=0,max;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
max=-100000;
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                if (max<temp){
                        max=temp;
                }
        }
temp=0;
}
cout<<max<<endl;
}
return 0;
}

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

int main(){
  int n;
  long a[5010];
  long s[5010];
  while(cin>>n && n){
    long 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;
}