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>

using namespace std;

int main()
{
	int a[5000];
	int left[5000], right[5000];
	int n;
	
	while (true) {
		cin >> n;
		if (n==0) break;
		
		for (int i=0; i<n; i++) cin >> a[i];
		
		int left_max = a[0];
		int left_max_pos = 0;
		left[0] = a[0];
		for (int i=1; i<n; i++) {
			left[i] = left[i-1] + a[i];
			if (left[i] > left_max) {
				left_max = left[i]; left_max_pos = i;
			}
		}
		int right_max = a[n-1];
		int right_max_pos = n-1;
		right[n-1] = a[n-1];
		for (int i=n-2; i>=0; i--) {
			right[i] = right[i+1] + a[i];
			if (right[i] > right_max) {
				right_max = right[i]; right_max_pos = i;
			}
		}
		
		int maximum = 0;
		for (int i = right_max_pos; i <= left_max_pos; i++) maximum += a[i];
		
		cout << maximum << endl;
	}
		
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    while(cin>>n, n) {
        int now, max;
        cin>>now;
        max=now;
        for(int i=1; i<n; i++) {
            int t;
            cin>>t;
            if(now<=0) now=t;
            else now+=t;
            if(max<now) max=now;
        }
        cout<<max<<'\n';
    }
    return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    int a[5000],sum[5001];
    sum[0]=0;
    for(int i=0;i<n;i++){
      cin>>a[i];
      sum[i+1]=sum[i]+a[i];
    }
    int ans=-1000000;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<=n;j++){
        ans=max(ans,sum[j]-sum[i]);
      }
    }
    cout<<ans<<endl;
  }
}

C++: #include <iostream>
int main(){
int a,b,c=1,d=0,z=-100000;
while(c=1){
	std::cin>>a;
	
	

	if(a==0){
		return 0;
	}
	int aa[a];
	for(int t=1;t<=a;t++){
		std::cin>>b;
	
		aa[t]=b;
	}
    
	for(int s=1;s<=a;s++){
		
			for(int l=s;l<=a;l++){
				d=d+aa[l];
				if(z<d){
					z=d;
				}
			}d=0;
		
		
	}
	std::cout<<z<<std::endl;
}
}

C++: #include<iostream>
using namespace std;
 
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int a[n+1];
    for(int i=0; i<n; i++) cin >> a[i];
    int Max = a[0];
 
    for(int i=0; i<n; i++){
      int sum=0;
      for(int j=i; j<n; j++){
    sum+=a[j];
    if(Max < sum) Max = sum;
      }
    }
    cout << Max << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const double PI = 3.141592653589793238462643383279502884L;
const int LARGE_PRIME = 1000000007;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i,a,cont,next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i,a,b,s) repfn(i,a,i<b,i+s)
#define repab(i,a,b) repby(i,a,b,1)
#define rep(i,b) repab(i,0,b)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  for (;;) {
    int n;
    vi v;

    cin >> n;
    if (!n)
      break;

    while (n--) {
      int tmp;
      cin >> tmp;
      v.pb(tmp);
    }

    vi w(v);
    int prev = 0;
    int accm = -LARGE_PRIME;
    while (prev != accm) {
      prev = accm;
      for (int i = 0; i < sz(v); i++) {
        w[i] = max(w[i], v[i] + w[i+1]);
        accm = max(accm, w[i]);
      }
    }
    cout << accm << endl;
  }
  return 0;
}

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

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

        int ret = -INF;
        for(int i=0; i<n-1; i++) {
            for(int j=i+1; j<n; j++) {
                ret = max(a[j] - a[i], ret);
            }
        }

        cout << ret << endl;
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int main(){
	int n;

	while(cin >> n){
		int max = 0;
		int soremade = 0;
		int mae = 0;
		int ima = 0;

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

		for(int i=1;i<n;i++){
			if(mae > soremade+mae){
				soremade = mae;
			}else{
				soremade += mae;
			}
			
			cin >> ima;
			
			if(max < ima+soremade){
				max = ima+soremade;
			}
			mae = ima;
		}

		cout << max << endl;
	}

	return 0;
}

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

int main() {

  long long int n = 0;

  while( cin >> n, n) {

    long long int max_ = -10000000;

    int array[n];
    for(int i = 0; i < n; i++){
      cin >> array[i];
    }

    for(int i = 0; i < n; i++){
      long long int sum = 0;
    
      for(int j = i; j < n; j++){
	sum += array[j];
	max_ = max(sum, max_);
      }
    }
    cout << max_ << endl;
  }

  return 0;

}

C++: #include <iostream>
#include <climits>
int main()
{
  while (1) {
    int n;
    std::cin >> n;
    if (n == 0) break;
    int max = -INT_MAX;
    int a[n];
    for (int i = 0;i < n; i++) {
      std::cin >> a[i];
    }
    for (int i  = 0; i < n; i++) {
      if (a[i] < 0) continue;
      int temp = a[i];
      for (int j = i + 1; j < n; j++) {
        temp += a[j];
        if (temp > max) max = temp;
      }
    }
    std::cout << max << std::endl;
  }
}

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

int a[5005];
int dp[5005];
int n;

int main(){



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

        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        long long p = 0;
        for(int i=0;i<n;i++){
            long long k = a[i];
            for(int j=i+1;j<n;j++){
                k = k + a[j];
                p =max(p,k);
            }
        }

        cout<<p<<"\n";

    }

}