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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MAX_N 5001
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, a[MAX_N], sum, MAX;

int main(){
	while (cin >> n&&n){
		MAX = -100000000;
		REP(i, n)cin >> a[i];
		for (int i = 0; i < n; i++){
			sum = a[i];
			for (int j = i + 1; j < n; j++){
				sum += a[j];
				MAX = max(MAX, sum);
			}
		}
		cout << MAX << endl;
	}
}

C++: #include <iostream>
#include <climits>
typedef long long ll;
using namespace std;
 
int main(){
    int n,a[5001];
    ll 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 <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 REP(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),b(n+1,0);
    int ans =-inf,sum=0;
    rep(i,n){
      cin >> a[i];
      sum += a[i];
      b[i+1] = sum;
    }
    rep(i,n+1){
      REP(j,i+1,n+1){
        ans = max(ans,b[j] - b[i]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
	int n;
	while (std::cin >> n) {
		if (n == 0) break;
		std::vector<int> a;
		for (int i = 0; i < n; i++) {
			int ai;
			std::cin >> ai;
			a.push_back(ai);
		}
		int max = a[0];
		for (std::vector<int>::iterator aitr = a.begin(); aitr != a.end(); aitr++) {
			for (std::vector<int>::iterator bitr = aitr; bitr != a.end(); bitr++) {
				int s = 0;
				for (std::vector<int>::iterator citr = aitr; citr != bitr + 1; citr++) {
					s += *citr;
				}
				max = s > max ? s : max;
			}
		}
		std::cout << max << std::endl;
	}

	return 0;
}

C++: //48
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int ans=-1<<30,seq=-1<<30;
    while(n--){
      int i;
      cin>>i;
      seq=max(seq+i,i);
      ans=max(ans,seq);
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int num;

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

		int tmpnum = 0;
		int currnum;
		int maxnum = 0;
		for( int i = 0; i < num; i++ ) {
			cin >> currnum;
			if( currnum + tmpnum > maxnum ) {
				maxnum = currnum + tmpnum;
			}
			
			if( currnum + tmpnum > currnum )
				tmpnum += currnum;
			else
				tmpnum = currnum;
		}
		cout << maxnum << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	int a[5000];
	while (cin >> n&&n != 0) {
		int sum3 = 0;
		for (int i = 0; i<n; i++)
			cin >> a[i];
		for (int i = 0; i<n; i++) {
			int sum = 0;
			int sum2 = 0;
			if(a[i] < 0) goto yo;
			for (int j = 0; j <= i; j++) {
				if (a[j]<0||(j<=1&&a[j-1]<0&&(a[j-1]+a[j])<0)) goto stop;;
				sum2 = 0;
				for (int z = j; z <= i; z++) {
					sum2 += a[z];
					if (sum<sum2) sum = sum2;
				}
			stop:;
			}
			yo:;
			if (sum3<sum) sum3 = sum;
		}
		cout << sum3 << endl;
	}
}

C++: // AOJ 0022 "Maximum Sum Sequence"(最大連続部分和) (パソコン甲子園 2003 本選 問題 026)
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    while (true) {
        int n;
        scanf("%d", &n);
        if (n == 0) {
            break;
        }
        
        int maxSum = -100000;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int an;
            scanf("%d", &an);
            sum += an;
            maxSum = max(maxSum, sum);
            if (sum < 0) {
                sum = 0;
            }
        }
        printf("%d\n", maxSum);
    }
    
    return 0;
}

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

using namespace std;

typedef long long int ll;
int main() {
  int N;
  while (cin >> N) {
    if (N == 0) break;
    int num[5000];
    ll m = 0;
    for (int i = 0; i < N; i++) {
      cin >> num[i];
    }
    for (int i = 0; i < N; i++) {
      ll sum = 0;
      for (int j = i; j < N; j++) {
        sum += num[j];
        m = max(m, sum);
      }
    }
    cout << m << 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=-100000*n-1;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 <iostream>
#include <cstdio.h>>
using namespace std;
int main (){
while (1){
long n,dset[5000],max=-99999,temp=0;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
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;
}
printf ("%d\n",max);
}
return 0;
}

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

int main(){
	long long int n;
	long long int i;
	long long int max;
	long long int sum[5000];
	long long int t;
	while(cin>>n,n){
		max=0;
		for(i=0;i<n;i++)cin>>sum[i];
		max=-100000;
		for(i=t=0;i<n;i++){
			if(t<0)t=sum[i];else t+=sum[i];
			if(max<t)max=t;
		}
		cout<<max<<endl;
	}
}

C++: #include <stdio.h>

int main(void) {
  while( 1 ) {
  long long n, ans = 0, now = 0;
  scanf("%lld", &n);
  if(!n) break;
  int a[n];
  for(i = 0; i < n; ++i) scanf("%d", &a[i]);
  for(i = 0; i < n; ++i) {
    now += a[i];
    if(now > ans) ans -= now;
    if(now < 0) now = 0;
  }
  if(!ans) {
    int max = -1000000;
    for(i = 0; i < n; ++i) if(max < a[i]) max = a[i];
    ans = max;
  }
  printf("%lld\n", ans);
  }
  return 0;
}