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 <stdio.h>

int main(void) {

  int n;

  int a[6000];

  while(1) {

    int max_a=0;
    int sum;

    int i,j;

    scanf("%d",&n);
    getchar();

    if(n==0) break;

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

    //for(i=0;i<n;i++) printf("%d ",a[i]);

    for(i=0;i<n;i++) {

      sum=0;

      for(j=i;j<n;j++) {

	sum+=a[j];

	if(max_a<sum) max_a=sum;
	//printf("%d ",max_a);
      }

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

  }



  return 0;

}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll n,a[5010],dp[5010],ans;

int main(void){
	while(1){
		cin>>n;
		if(n==0)break;
		reg(i,1,n)cin>>a[i];
		dp[0]=0;
		reg(i,1,n)dp[i]=max(dp[i-1]+a[i],a[i]);
		ans=-1e18;
		reg(i,1,n)ans=max(ans,dp[i]);
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  int n, x, max_;
  int dp[5001];
  while(1){
    cin >> n;
    if(!n) break;
    max_=0; dp[0]=0;
    for(int i=1; i<=n; ++i){
      cin >> x;
      dp[i] = max(x, dp[i-1]+x);
      max_ = max(max_, dp[i]);
    }
    cout << max_ << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int A[50000]={0};
int S[50000]={0};

int main(){
  int n;

  while(cin >> n&&n>0){
    for(int i=0;i<n;++i) cin >> A[i];

    long maxsum = 0;
    for(int i=0;i<n;++i){
      for(int j=i;j<n;++j){
        long sum = 0;
        for(int k=i;k<=j;++k){
          sum += A[k];
        }
        if(sum>maxsum) maxsum = sum;
      }
    }
    cout << maxsum << endl;
  }

  return 0;
}

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

int main()
{

	int n, num;
	vector< long int > a;

	while( 1 ) {

		int Max = -1000001;

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

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		//?????§???
		for( int i = 1; i <= n; i++ ) {
		
			a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

			if ( a[i] > Max ) {
				Max = a[i];
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}

C++: #include<stdio.h>
int main(void){
   int n, a, i, max = 0, sum[100][100];
   scanf("%d", &n);
   for ( i = 0; i < n; i++ ) {
       scanf("%d", &a);
       if ( i == 0 )sum[0][0] = a;
       else sum[0][i] = sum[0][i - 1] + a;
       if ( max < sum[0][i]) max = sum[0][i];
       printf("sum:%d max:%d\n", sum[0][i], max);
   }
   printf("%d", max[0]);
   return 0;
}

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

using namespace std;

int main(){
  int n,x[5000];
  while(1){

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

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

  int now=0;
  int Max=-100001,tmp;
  for(int i = 0;i < n; i++){
    now+=x[i];
    tmp=now;

    for(int j=0;j < i;j++){
      Max=max(Max,now);
      now-=x[j];
      }

    now=tmp;
    }
  cout << Max << endl;
} 

  return 0;
}

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

int main()
{
	int n;
	while(cin>>n,n)
	{
		int data[n],dp[n+1];
		int tmp=0,ans;
		for (int i = 0; i < n; ++i)
		{
			cin>>data[i];
		}
		dp[0]=data[0];
		for (int i = 1; i < n; ++i)
		{
			dp[i]=max(dp[i-1]+data[i],data[i]);
			ans=max(ans,dp[i]);
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

long long a[5000];
int main(){
	int n;
	while(cin >> n && n){
		long long ans = 1e9;
		for(int i = 0 ; i < n ; i++) cin >> a[i] , ans = min(ans, a[i]);
		long long sub = 0;
		for(int i = 0 ; i < n ; i++){
			sub += a[i];
			if( sub < 0 ){
				sub = 0;
			}else{
				ans = max(ans,sub);
			}
		}
		cout << ans << endl;
	}
}

C++: #include <cstdio>
#include <algorithm>
#include <functional>
#include <stack>
#include <cmath>
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define llong long long

int main() {
  while(1){
    int n;
    scanf("%d",&n);
    if(n == 0) break;
    int a[n];
    REP(i,n) scanf("%d",a+i);
    int max = 0;
    int sum = 0;
    REP(i,n) {
      sum += a[i];
      if(max < sum) max = sum;
      if(sum < 0) sum = 0;
    }
    if(max < sum) max = sum;
    printf("%d\n",max);
  }
  return 0;
}

C++: #include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    int n; cin >> n;
    if (n == 0) return;
    vi64 a(n); cin >> a;
    vi64 sums(n + 1);
    rep(i, n) sums[i + 1] += sums[i] + a[i];
    i64 ma = -1e18;
    for (int l = 0; l < n; l++)
    for (int r = l + 1; r <= n; r++) {
      amax(ma, sums[r] - sums[l]);
    }
    cout << ma << '\n';
  }
}