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 <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		long long int a[5000], sum = 0, hold = 0;
		for(int i = 0;i < n;i++){
			cin >> a[i];
		}
		hold = a[0];
		for(int i = 0;i < n;i++){
			for(int j = i;j < n;j++){
				sum += a[j];
				if(hold < sum){
					hold = sum;
				}
			}
			sum = 0;
		}
		cout << hold << endl;

	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
while (1){
long n,dset[5000],temp=0,MINEdset[5000],max,h[5000],b=0;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
max=dset[0];
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                MINEdset[j]=temp;
        }
        for (int j=i;j<n;j++){
                if (max<MINEdset[j]){
                        max=MINEdset[j];
                }
        }
        h[b]=max;
        b++;
        temp=0;
}
for (int i=0;i<=b;i++){
        if (max<h[i]){
                max=h[i];
        }
}
cout<<max<<endl;
}
return 0;
}

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

int t[5002];

int main(){
  int n;

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

    int ans = INT_MIN;

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

      for(int j = i; j < n; j++){
        sum += t[j];
        ans = max(ans, sum);
      }
    }

    cout << ans << endl;
  }
}

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

int main(){
    int n;
    while(cin >> n && n){
        vector<int> a(n,0);
        for(int i=0; i<n; ++i){
            cin >> a[i];
        }
        vector<int> dp(n,0);
        dp[0] = a[0];
        int max = 0;
        for(int i=1; i<n; ++i){
            if(dp[i-1]>0){
                dp[i] = dp[i-1] + a[i];
            } else {
                dp[i] = a[i];
            }
            if(max<dp[i]){
                max = dp[i];
            }
        }
        cout << max << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main (){
while (1){
long n,dset[5000],temp=0,MINEdset[5000],max=0,h[5000],b=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];
                MINEdset[j]=temp;
        }
        for (int j=i;j<n;j++){
                if (max<MINEdset[j]){
                        max=MINEdset[j];
                }
        }
        h[b]=max;
        max=0;
        b++;
        temp=0;
}
max=-99999;
for (int i=0;i<=b;i++){
        if (max<h[i]){
                max=h[i];
        }
}
cout<<max<<endl;
max=0;
}
return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 1000;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(1){
		ll n;cin>>n;
		if(n==0)break;
		ll ans;cin>>ans;
		priority_queue<ll> q;
		ll w=ans;
		q.push(-ans);
		FOR(i,0,n-1){
			ll k;cin>>k;
			w += k;
			ans = max(ans,w+q.top());
			ans = max(ans,w);
			q.push(-w);
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>

using namespace std;

int main(void){
	int n;
	long long int a[5000]={0};
	while(cin >> n){
		long long int max = -100000;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			cin >> a[i];
		}
		for(int i=0;i<n;i++){
			long long int sum = 0;
			for(int j=0;i+j<n;j++){
				sum += a[i+j];
				if(j!=0&&max < sum) max = sum;
			}
		}
		cout << max << "\n";
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(int argc, const char * argv[])
{
    while (1) {
        int n; scanf("%d", &n);
        if (n == 0) break;
        long a[n], b[n], tmp = 0;
        for (int i = 0; i < n; i++) {
            scanf("%ld", &a[i]);
            b[i] = 0;
        }
        for (int i = 0; i < n; i++) {
            for (int k = 0; k <= i; k++) {
                b[i] += a[k];
            }
        }
        for (int i = n-1; i > 0; i--) {
            for (int k = i-1; k >= 0; k--) {
                if (i == n-1) {
                    tmp = (b[i] - b[k] + a[k]);
                }
                if (tmp < (b[i] - b[k] + a[k])) {
                    tmp = (b[i] - b[k] + a[k]);
                }
            }
        }
        cout << tmp << endl;
    }
    return 0;
}

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;
	z=0;
}
}

C++: #include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
#define NMAX 5100

//int dp[NMAX][NMAX];
int a[NMAX];

int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0)break;
        memset(a,0,sizeof(int)*NMAX);

        for(int i =1;i<=n;++i)
        {
            cin >> a[i];
        }
        int sum = 0,ans = 0;
        for(int first = 1;first<=n; ++first)
        {
            for(int last = first;last<=n;++last)
            {
                sum += a[last];
                if(ans<sum) ans = sum;
            }
            sum = 0;
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(void){
	int n;
	int a[5000];
	while(cin>>n,n){
		for(int i=0;i<n;i++)cin>>a[i];
		int sum=0;
		int m=a[0];
		for(int i=0;i<n;i++){
			sum+=a[i];
			m=max(m,sum);
			sum= sum>=0 ? sum : 0;
		}
		cout<<m<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int i;
	long max;
	long total;
	int a[5010];
	int n;
	
	while (scanf("%d", &n), n != 0){
		max = 0;
		total = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
			total += a[i];
			if (max < total){
				max = total;
			}
			if (total < 0){
				total = 0;
			}
		}
		printf("%d\n", max);
	}
	return (0);
}