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 <algorithm>
using namespace std;
int main(void){
        int n; int num[5000]; int max1=-100000;
        while(cin >> n ,n){
                for(int i=0; i<n; i++)
                        cin >> num[i];
		max1=num[0];
                for(int i=0; i<n; i++){
                        int sum=0;
                        for(int j=i;j<n;j++){
                                sum+=num[j];
                                max1=max(max1,sum);
                        }
                }
                cout << max1 << endl;
        }
 
 
}

C++: #include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <cmath>
#include <sstream>
#define F first
#define S second
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int main() {
	int n;
	while (cin >> n && n) {
		vector<long long> a;
		a.push_back(0);
		for(int i=0;i<n;i++)
		{
			long long x;
			cin>>x;
			a.push_back(x);
		}
		for(int i=1;i<a.size();i++)
		{
			a[i]+=a[i-1];
		}
		long long ans=0;
		for(int r=0;r<a.size();r++)
		{
			for(int l=r+1;l<a.size();l++)
			{
				ans=max(ans,a[l]-a[r]);
			}
		}
		cout<<ans<<endl;
	}




	return 0;
}

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

C++: #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int N;
        cin>>N;
        if(!N)break;
        int rui[10000]={0};
        for(int i=1;i<=N;i++){
            int a;
            cin>>a;
            rui[i]=rui[i-1]+a;
        }
        int ans=-2000000000;
        for(int i=0;i<=N;i++){
            for(int j=i;j<=N;j++)ans=max(ans,rui[j]-rui[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>
typedef long long ll;
using namespace std;
 
int main(){
    int n,a[5001];
    ll ans;
    a[0]=0;
    while(cin>>n&&n){
        ans = INT_MIN;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            a[i] += a[i-1];
        }
        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                ans = max(ans,a[j]-a[i-1]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

C++: //! Bismillahi-Rahamanirahim.
/** ========================================**
 ** @Author: Md. Abu Farhad ( RUET, CSE'15)
 ** @Category:
/** ========================================**/

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

#define ll long long

#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)
#define scc(x) scanf("%[^\n]s",x); // For charecter string input , It will  read all charecter untill Enter new line .

#define pfi(x) printf("%d",x)
#define pfl(x) printf("%lld\n",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) printf("Case %d: ",x)
#define ps printf(" ")
#define pn printf("\n")
#define pb(x) push_back(x)
#define ppb(x) pop_back(x)
#define pf(x) push_front(x)
#define ppf(x) pop_front(x)

#define Pi               2*acos(0.0)
#define ms(a,b)       memset(a, b, sizeof(a))
#define EPS           10E-10
#define ff              first
#define ss              second
#define sqr(x)        (x)*(x)



ll v[5005];

ll max_subarray( ll n)
{
    ll ans=-1000000, curr_max=0;
    for(ll i=0; i<n; i++)
    {
        curr_max=max(v[i], curr_max+v[i]);
        ans=max(ans, curr_max);
    }
    return ans;
}



int main()
{

    ll m,n,t,b,c,d,i,j,k,x=0,y,z;
    while(1)
    {
        cin>>n;
        if(n==0) return 0;
        else
        {
            for(i=0; i<n; i++)
            {
                cin>>v[i];
            }
            cout<<max_subarray( n )<<endl;
            for(i=0; i<n; i++) v[i]=0;
        }
    }

    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 = -1000000;
    int prefix_sum[50002]={0};
    prefix_sum[0] = 0;
    for(int i=1;i<n+2;++i){
      prefix_sum[i]=prefix_sum[i-1]+A[i-1];
    }
    for(int i=0;i<n+2;++i){
      for(int j=i;j<n+2;++j){
        if(prefix_sum[j]-prefix_sum[i]>maxsum){
          maxsum = prefix_sum[j]-prefix_sum[i];
        }
      }
    }
    cout << maxsum << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n; int const N = 5000;
  while(cin >> n){
    if(n == 0){return 0;}
    int  a[N],s,num,st,tmp;
    for(int i=0;i<n;i++)
      cin >> a[i];
    tmp=a[0];
    for(st = 0;st<n;st++){
      s = 0;
      for(int i = st;i<n;i++){
	s = s+a[i];
	tmp =max(s,tmp);
      }
    }
    cout << tmp<<endl;
  }
}

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

using namespace std;

int main(int argc, char *argv[]) {
  vector<int> maxsums, a;
  int n, tmp;

  a.reserve(5000);
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    for (int i = 0; i < n; i++) {
      tmp = a[i];
      for (int j = i + 1; j < n; j++) {
        tmp += a[j];
        if (tmp > a[i])
          a[i] = tmp;
      }
    }

    int max = a[0];
    for (int i = 0; i < n; i++)
      if (max < a[i])
        max = a[i];
    maxsums.push_back(max);
  }

  for (int i = 0; i < maxsums.size(); i++)
    cout << maxsums[i] << endl;
  return 0;
}