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 <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;

int main (void){
  
    int number;
    int max;
    int answer[500] = {0};
    int l = 0;
    while(cin >> number,number)
    {
        int a[5010] = {0};
        vector<int>tempmax(500.500);
        vector<int>tempmax2(1000);
        REP(i,number)
        cin >> a[i];
        for(int i = number;i>=0;i--)
            for(int j = 0; j<i;j++)
            {
                tempmax[i] +=a[j];
            }
        for(int k = 0;k<number;k++)
            for(int m = k;m<number;m++)
            {
                if(k == m)
                    tempmax2[k] = a[k];
                else if(tempmax2[k]+a[m] >= tempmax2[k])
                    tempmax2[k]+= a[m];
                else
                    break;
            }
        sort(tempmax.begin(),tempmax.end(),greater<int>());
        sort(tempmax2.begin(),tempmax2.end(),greater<int>());
        if(tempmax[0]>tempmax2[0])
            answer[l] = tempmax[0];
        else
            answer[l] = tempmax2[0];
        l++;
    }
    REP(i,l)
    cout << answer[i] << endl;
    return 0;
}

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];
        }
        // ????????£?¶??????????????????§??£?¶???????dp??¨?????????
        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++: /*************************************************************************
	> File Name: 1.cpp
	> Author: ralph
	> Mail: 1694487365@qq.com
	> Created Time: 2018年12月26日 星期三 19时30分31秒
 ************************************************************************/

#include<bits/stdc++.h>
using namespace std;
int num[100000],dp[100000];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
        {
            cin>>num[i];
            dp[i]=max(dp[i-1],0)+num[i];
        }
        int maxn=0;
        for(int i=1;i<=n;i++)
        {
            if(dp[i]>maxn) maxn=dp[i];
        }
        cout<<maxn<<endl;
    }
}

C++: #include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>

using namespace std;

int main(){
	int n, tmp, max;
	int sum;
	vector<int> v;

	while(cin >> n){
		if(n == 0){
			break;
		}
		v.clear();
		while(n--){
			cin >> tmp;
			v.push_back(tmp);
		}
		max = v[0];
		for(int i = 0; i < v.size(); i++){
			sum = 0;
			for(int j = i; j < v.size(); j++){
				sum += v[j];
				if(sum > max){
					max = sum;
				}
			}
		}
		cout << max << endl;
	}

	return 0;
}

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

using namespace std;
int length=0;
int* sums;

int main(){
  string str="";
  while(1){
  cin>>length;
  if(length==0)break;
  sums=new int[length+1];
  sums[0]=0;
  int s=0;
  for(int i=0;i<length;i++){
    int v=0;
    cin>>v;
    s+=v;
    sums[i+1]=s;
  }
  int max=INT_MIN;
  for(int i=0;i<length+1;i++){
    for(int j=i;j<length+1;j++){
      int diff=sums[j]-sums[i];
      if(diff>max){
        max=diff;
      }
    }
  }
  str+=to_string(max)+"\n";
  }
  cout<<str;
  return 0;
}

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

int main(){
	int n;
	int sequence[5000];
	int ans;
	int sum;

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

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

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

long long a[5000];

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

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		int sum=0,a[5001],ans=-999999999;
		vector<int>anss(0);
		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(sum,ans);
				//anss.push_back(sum);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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];
        }
        // ????????£?¶??????????????????§??£?¶???????dp??¨?????????
        vector<int> dp(n,0);
        dp[0] = a[0];
        int max = 0;
        for(int i=0; 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>
#include<cstdio>
using namespace std;

int main(){
  int i,j,n,max,sum,a[5001];
  while(1){
    cin>>n;
    if(n==0)break;
    for(i=0;i<n;i++){
      cin>>a[i];
    }
    max=a[0];
    for(i=0;i<n;i++){ 
      sum=0;
      for(j=i;j<n;j++){
	sum+=a[j];
	if(max<sum)max=sum;	
      }
    }
    cout<<max<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	for (;;){
		int a,goukei=0,max=-999999999,b;
		cin>>a;
		if (a==0)break;
		int data[a+1]={0};
		for (int A=1;A<=a;A++){
			cin>>data[A];
			if (max<data[A])max=data[A];
			goukei+=data[A];
			data[A]=goukei;
			if (max<data[A])max=data[A];
		}max=-999999999;
		for (int A=3;A<a;A++){
			b=A-2;
			for (int B=b;B>0;B--){
				goukei=0;
				goukei=data[A]-data[B];
				if (goukei>max) max=goukei;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}