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>
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;
}
}

C++: #include <algorithm>
#include <iostream>
using namespace std;
int a[5010];
int main(){
	int i,n,max_so_far,max_ending_here,amax;//maximum subarray problem
	cin>>n;
	while(n!=0){

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

		max_ending_here=0;
		max_so_far=0;
		amax=-100000;

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

	if(amax < 0){cout << amax <<endl;}
	else{cout << max_so_far << endl;}
	cin>>n;//kousinn
	}
}

C++: #include <iostream>

using namespace std;

int main() {
  int n;
  while (cin >> n && n != 0) {
    int *a = new int[n];
    int max, t;
    for (int i = 0; i < n; i++) {
      cin >> t;
      a[i] = t;
    }
    max = -1000000;
    for (int j = 0; j < n; j++) {
      for (int k = j, t = 0; k < n; k++) {
        t += a[k];
        if (max < t) max = t;
      }
    }
    delete [] a;
    cout << max << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
  int n,sum = 0,ans,sumkeep;
  
  while(cin >> n){
    if(n == 0)break;
    
    ans = 0;
    sumkeep = 0;

    int a[n];
    
    for(int i = 0;i < n;i++){
      cin >> a[i];
    }
    
    for(int i = 0;i < n;i++){
      sumkeep = 0;
      for(int j = i;j < n;j++){
	sumkeep += a[j];
	if(i == 0){
	  ans = sumkeep;
	}
	else if(ans < sumkeep){
	  ans = sumkeep;
	}
      }
    }
    cout << ans << endl;
  }
}

C++: #include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n&&n!=0)
else
{
int a[n];
int A=0;
int R=-100000;
for(int h=0;h<n;h++)
{
	cin>>a[h];
}
for(int i=0;i<n;i++)
{
	for(int j=0;j<n-i;j++)
	{
	for(int k=i;k<=j;k++)
	{
		A=A+a[k];
		
	}	
	if(R<A)
	{
		R=A;
	}
	A=0;
	}
}
cout<<R<<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[5001];
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-2]);
			}
		}
		cout<< ans <<endl;
	}
}

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

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    int N;

    while(cin >> N, N)
    {   
        vector<ll> a(N);
        rep(i, N) cin >> a[i];        

        vector<ll> dp(N, 0);

        dp[0] = a[0];

        rep(i, N - 1)
            dp[i + 1] = max(dp[i] + a[i + 1], a[i + 1]);

        ll ans = -llINF;

        rep(i, N) ans = max(dp[i], ans);

        cout << ans << endl;
        
    }

    return 0;
}

C++: #include <stdio.h>

int main()
{
        int n, i, j, k;
        double a[5000], sum, max;

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

                max = 0;
                for (j = 0; j < n; j++) {
                        sum = 0;
                        for (i = j; i < n; i++) {
                                sum += a[i];
                                if (sum > max) {
                                        max = sum;
                                }
                        }
                }
                printf("%d\n", max);
        }
        return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main_(void)
{
	int n, a[5001];
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int goukei = 0, ryuta = -10000000;
	for (int i = 1; i <= n; i++)
	{
		goukei = 0;
		for (int j = 1; j <= n; j++)
		{
			goukei = goukei+a[j];
			ryuta = max(goukei, ryuta);
		}
	}
	cout << ryuta << endl;
	return 0;
}

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

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

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

vector<int> num;

int main(void){
  while(true){
    int maximum = 0, n;
    cin >> n;
    if(!n)  break;
    num.clear();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < num.size(); i++){
      int sum = num[i];
      maximum = num[i];
      for(int j = i + 1; j < num.size(); j++){
        sum += num[j];
        if(sum > maximum) maximum = sum;
      }
      if(sum > maximum) maximum = sum;
    }
    cout << maximum << endl;
  }
  return 0;
}

C++: #include<stdio.h>

int N[5001]={};
int main(){

int n,x;

while(1){
scanf("%d",&n);if(n==0)break;


for(int i=0;i<n;i++)
scanf("%d",&N[i]);
int t=0,s=0;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
s+=N[j];if(t<s)t=s;
}
s=0;
}
printf("%d\n",t);
}
return 0;
}

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

int main(void){
	int i,j,k,n,a[5000],ans;
	while(1){
	cin >> n;
	if(n == 0) break;
	ans = 0;
	a[0] = 0;
	k = 0;
	for(int t=0;t<n;t++){
		int x = 0;
		cin >> x;
		if(a[k] == 0) a[k] += x;
		else if(a[k] > 0 && x > 0 || a[k] < 0 && x < 0) a[k] += x;
		else a[++k] = x;
	}
	k++;
	if(a[0] < 0){
		for(i=0;i<k-1;i++) a[i] = a[i+1];
		k--;
	}

	for(i=1;i<k-1;i++){
		if(a[i] < 0 && a[i] + a[i+1] > 0){
			a[i-1] += a[i] + a[i+1];
			for(j=i;j<k-2;j++) a[j] = a[j+2];
			k -= 2;
		}
	}

	for(i=0;i<k;i++) ans = max(ans,a[i]);

	cout << ans << endl;
}
	return 0;
}