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>
#include <algorithm>
using namespace std;

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

    int ans = -(1<<30);
    for (int i=0; i<n; i++) {
      int sum = 0;
      for (int j=i; j<n; j++) {
        sum += x[j];
        ans = max(ans, sum);
      }
    }
    cout << ans << endl;
  }
}

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


int main() {
    int n;
    std::cin >> n;
    while (n != 0) {
        std::vector vec(n+1, 0);
        int x;
        for (int i = 1; i <= n; ++i) {
            std::cin >> x;
            vec[i] = x;
        }
        std::vector<int> sum;
        sum.assign(n+1, 0);
        sum[1] = vec[1];
        for (int i = 1; i < n; i++) {
            sum[i+1] = sum[i] + vec[i+1];
        }
        int ans = -1000000000;
        for (int l = 1; l <= n; ++l) {
            for (int r = l; r <= n; ++r) {
                ans = std::max(ans, sum[r] - sum[l-1]);
            }
        }
        std::cout << ans << std::endl;
        std::cin >> n;
    }
}

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

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

int main(){
        int n,a[5010];
        while(cin >> n && n){
                int buf,j=0;
                for(int i=0; i<n; i++){
                        cin >> buf;
                        if(i>0 && a[j]*buf>=0) a[j] += buf;
                        else a[++j] = buf;
                }
                long max = 0;
                for(int i=0; i<j; i++){
                        for(int k=i; k<=j; k++){
                                long sum = 0;
                                for(int l=i; l<=k; l++){
                                        sum += a[l];
                                }
                                max = (max > sum)? max:sum;
                        }
                }
                cout << max << endl;
        }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
long long dp[6000],n,a[6000],i,maxm;
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=1;i<=n;i++)cin>>a[i];
    dp[1]=maxm=a[1];
    for(int i=2;i<=n;i++){
      if(dp[i-1]>=0)dp[i]=dp[i-1]+a[i];
      else dp[i]=a[i];
       
      maxm=max(dp[i],maxm);
    }
    cout<<maxm<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#ifdef dbg
#include "./printer.hpp"
#else
#define dump(x) void(0)
#endif

#define MOD 1000000007
using namespace std;
#define ll long long
inline long  toInt(string s) {long  v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int main(){
  ll n;
  while(cin >> n && n){
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
      cin >> a[i];
    }
    vector<ll> b(n);
    b[0] = a[0];
    for(ll i = 1; i < n; i++){
      b[i] = max(b[i-1] + a[i], a[i]);
    }

    ll ans = 0;
    for(ll i = 0; i < n; i++){
      ans = max(ans, b[i]);
    }
    cout << ans << '\n';
    
  }

}

C++: #include<iostream>
#include<vector>
using namespace std;
int main() {
	int a,i,j,k,n;
	long long max, sum;
	vector<int> s;
	while (cin >> n) {
		if (n == 0)break;
		s.clear();
		max = 0;
		for (i = 0; i < n; i++) {
			cin >> a;
			s.push_back(a);
		}
		for (j = 0; j < n; j++) {
			sum = 0;
			for (k = j; k < n; k++) {
				sum += s[k];
				if (sum > max)max = sum;
			}
		}
		cout << max << endl;
	}
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	while(n != 0){	

		int a[n];
		int sum[n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				sum[i][j] = 0;
			}
		}

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

		for(int i = 0; i < n; i++){
			sum[i][0] = a[i];
			for(int j = 0; j < n - i; j++){
				sum[i][j+1] = sum[i][j] + a [i+j+1];
				maximum = max(maximum, sum[i][j]);
			}
		}
		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}

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

int main(){
    int n;
    while(cin>>n && n!=0){
        int* A=new int[n];
        int* S=new int[n+1];
        S[0]=0;
        for(int i=0;i<n;++i){
            cin>>A[i];
            S[i+1]=A[i]+S[i];
        }

        int maxsum=0;
        for(int i=0;i<n;++i){
            for(int j=i+1;j<n+1;++j){
                maxsum=(S[j]-S[i]>maxsum?S[j]-S[i]:maxsum);
            }
        }

        cout<<maxsum<<"\n";
        delete[] A;
        delete[] S;
    }
}

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

int do_stuff(int n)
{
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }

    int max_so_far = 0;
    int max_ending_here = 0;

    for (int i = 0; i < n; ++i) {
        int curr = a[i];
        max_ending_here = max(max_ending_here + curr, 0);
        max_so_far = max(max_so_far, max_ending_here);
    }

    if (max_so_far == 0) {
        max_so_far = *max_element(a.begin(), a.end());
    }
    return max_so_far;
}

int main(int argc, char* argv[])
{
    //freopen("input.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    while (n != 0) {
        int ans = do_stuff(n);
        printf("%d\n", ans);
        scanf("%d", &n);
    }
    return 0;
}

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

vector<int> num;
int dp[5000];

void init(){
  for(int i = 0; i < 5000; i++){
    dp[i] = 0;
  }
  num.clear();
}

int main(void){
  while(true){
    int maximum = 0, n;
    cin >> n;
    if(!n)  break;
    init();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < n; i++){
      dp[i] = max(dp[i-1] + num[i], num[i]);
    }
    
    for(int i = 0; i < n; i++){
      if(dp[i] > maximum) maximum = dp[i];
    }

    cout << maximum << endl;
  }
  return 0;
}