Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

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

using namespace std;

int main(){
  vector<int> sum;
  int n;
  int input;

  while(cin>>n){
    if(n==0)break;
    vector<int> array;
    for(int i=0;i<n;i++){
      cin>>input;
      array.push_back(input);
    }
    vector< vector<int> > now;
    vector<int> maxarray;
    for(int i=0;i<n;i++){   //start point
      for(int k=i;k<n;k++){  //end point
	int a=0;
	for(int j=i;j<=k;j++){
	a+=array[j];
      }
      now[i].push_back(a);
      }
    }
    for(int i=0;i<n;i++){
      int ma=0;
      for(int j=i;j<n;j++){
	if(i<n-1){
	  ma=max(now[i][j],now[i][j+1]);
	}
      }
      maxarray.push_back(ma);
    }
    int ma1=0;
    for(int i=0;i<n;i++){
      if(i<n-1){
	ma1=max(maxarray[i],maxarray[i+1]);
      }
    }
    sum.push_back(ma1);
  }
    vector<int> ans;
  int i=0;
  int size=sum.size();
  while(!sum.empty()){
    ans.push_back(sum[size-1-i]);
    sum.pop_back();
    i++;
  }
  i=0;
  while(!ans.empty()){
    cout<<ans[size-1-i]<<"\n";
    ans.pop_back();
    i++;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define BE(c) c.begin(),c.end()
#define PB push_back
#define F first
#define S second
#define BEB(s) s
using namespace std;
int main(){
	int n,d[5001];
	while(1){
		cin>>n;
		if(n==0)break;
		d[0]=0;
		FOR(i,1,n+1){
			int a;
			cin>>a;
			d[i]=d[i-1]+a;
		}
		int ans=INT_MIN;
		FOR(i,1,n+1)REP(j,i)ans=max(ans,d[i]-d[j]);
		cout<<ans<<endl;
	}
	return 0;
}

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

// warning: include *e
int getBackMaxSum(int* s, int *e) {
	int sum = *e, maxSum = 0xffffffff;
	for (e--; s <= e; e--) {
		sum += *e;
		maxSum = max(sum, maxSum);
	}
	return maxSum;
}

int main () {
	while (cin >> n, n) {
		int a[n], maxSum = 0xffffffff;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			maxSum = max(maxSum, getBackMaxSum(a, a + i));
		}
		cout << maxSum << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <climits>
typedef long long ll;
using namespace std;
 
int main(){
    int n,a[5001];
    long long ans;
    a[0]=0;
    while(cin>>n&&n){
        ans = INT_MIN;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            a[i] += a[i-1];
        }
        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                ans = max(ans,a[j]-a[i-1]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
long n,i,a[5000],t,x;
while(cin>>n,n){
for(i=0;i<n;i++)cin>>a[i];
x=-100000;
for(t=i=0;i<n;i++){
if(t<0)t=a[i];else t+=a[i];
if(x<t)x=t;
}
cout<<x<<endl;
}
return 0;
}

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

int main() {
	int n;
	while(cin >> n, n) {
		vector<int> v(n);
		for(int i = 0; i < n; i++) cin >> v[i];
		int ans = -100000;		
		for(int i = 0; i < n; i++) {
			int sum = 0;
			for(int j = i; j < n; j++) {
				sum += v[j];
				if(ans < sum) ans = sum;			
			}
		}
		cout << ans << endl;
	}
}

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

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

C++: #include <iostream>
#include <algorithm>
#include <limit.h>
using namespace std;

int main(){
	int a[10000],n,s,m;
	while(cin>>n,n){
		m=INT_MIN;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=1;i<=n;i++){
			for(int j=0;j<n-i+1;j++){
				s=0;
				for(int k=0;k<i;k++){
					s+=a[j+k];
				}
				m=max(m,s);
			}
		}
		cout<<m<<endl;
	}
}

C++: #include<iostream>
#include<string.h>

int n;
int a[5001];

void add( int i, int x )
{	
	while( i <= n ){
		a[i] += x;
		i += i & (-i);
	}
	
	return;
}

int sum( int i )
{
	if( i == 0 ) return 0;

	int s = 0;
	while( i > 0 ){
		s += a[i];
		i -= i & (-i);
	}
	
	return s;
}

int main()
{
	while( 1 ){
		memset( a, 0, sizeof( a ) );
	
		std::cin >> n;
		if( !n ) break;
		
		for( int i = 1; i <= n; i++ ){
		 	int x;
			std::cin >> x;
			add( i, x );
		}
		
		int ans = -100001;
		
		for( int i = 0; i < n; i++ ){
		 	for( int j = i + 1; j <= n; j++ ){
				ans = std::max( ans, sum( j ) - sum( i ) );
			}
		}
		
		std::cout << ans << std::endl;
	}
	
 	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;


int ans;
int d[5000];
int di;


int dfs(int n, int v)
{
  if(n < 0)
    return v;
  return max(v, dfs(n - 1, v + d[n]));
}


int main()
{
  while(true)
  {
    int n;
    ans = 0;
    di = 0;
    cin >> n;
    if(!n)
      break;
    for(int i = 0; i < 5000; i++)
      d[i] = 0;
    for(int i = 0; i < n; i++)
    {
      int x;
      cin >> x;
      if((x > 0 && d[di] < 0) || (x < 0 && d[di] > 0))
      {
        di++;
      }
      d[di] += x;
    }
    for(int i = 0; i <= di; i++)
    {
      ans = max(ans, dfs(i, 0));
    }
  
    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
    for(;;){
        int n;
        int a[10000]={0};
        cin>>n;
        if(n==0)break;
        long long int sum=0;
        long long int ans=-1000000;
        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];
                ans=max(ans,sum);
            }
        }
        cout<<ans<<endl;

    }


	return 0;
}

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 sum[3000];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;
		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;
	}
}