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<vector>

using namespace std;

int main(){

  int n;


  while(cin >> n){
    if(n == 0) break;
    vector<int> V;
    int status = 1;
    int in;
    int sum = 0;
    for(int i = 0; i < n; i++){
      cin >> in;
      if(i == 0){
	if(in < 0) status = -1;
	else status = 1;

      } else {	
	if(in < 0 && status == 1){
	  status = -1;
	  V.push_back(sum);
	  sum = 0;
	}else if(in > 0 && status == -1){
	  status = 1;
	  V.push_back(sum);
	  sum = 0;
	}
      }
      sum += in;
    }

    V.push_back(sum);

    int max = -1000001;
    
    for(int i = 0; i < V.size(); i++){
      sum = 0;
      for(int j = i; j < V.size(); j++){
	sum += V[j];
	if(max < sum) max = sum;
      }
    }
    
    cout << max << endl;
  }
  return 0;
}

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

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

C++: #include<iostream>
#include<cstdio>
using namespace std;
#define int long long
signed main(){
        int n;
        while( scanf("%lld", &n) != EOF ){
                if(n==0) break;
                int max=-100001;
                int now=0;
                for(int i=0;i<n;i++){
                        int t;
                        scanf("%lld", &t);
                        if(now+t>t)now+=t;
                        else now = t;
                        if(now>max) max=now;
                }
                printf("%lld\n",max);
        }
        return 0;
}

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

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

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 1000000000
#define EPS 1.0e-10

using namespace std;

typedef long long ll;

int n;

int main()
{
	while (cin >> n) {
		if (n == 0)return 0;
		ll d[5250];
		
		d[0] = 0;
		int a;
		for (int i = 1; i <= n; i++) {
			cin >> a;
			d[i] = d[i - 1] + a;
		}
		ll max = -INF;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < i; j++) {
				if (d[i] - d[j] > max)max = d[i] - d[j];
			}
		}
		cout << max << endl;
	}

}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
#include<numeric>
using namespace std;


int main(void) {

  int n;
  while(cin >> n){
    if( n == 0 ) break;

    vector<int> a(n+1, 0);
    int sum = 0;
    for(int i=0; i<n; i++){
      int tmp;
      cin >> tmp;
      sum += tmp;
      a[i+1] += sum;
    }

    int mx = a[1];
    for(int i=0; i<n+1; i++){
      for(int j=i; j<n+1; j++){
        cerr << a[j]-a[i] << " ";
        mx = max(mx, a[j]-a[i]);
      }
    }
    cout << mx << endl;

  }

  return 0;
}

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

double before_degree = 0;;

int main(void){

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

        int ans = 0,tmp;
        vector<int> num(5010,0);
        for(int i = 0;i < n;i++){
            cin >> num[i];
        }
        vector<int> dp(5010,0);
        dp[0] = num[0];
        ans = dp[0];
        for(int i = 1;i < n;i++){
            dp[i] = max(num[i],dp[i-1]+num[i]);
            ans = max(ans,dp[i]);
        }


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

C++: #include <iostream>
#include <stack>
#include <stdio.h>
#include <cmath>
#include <utility>
using namespace std;
int main()
{
    int n;
	while(cin>>n&&n){
		int a[5000]={},sum[5000]={},m=-1000000;
		for(int i=0;i<n;i++){
			cin>>a[i];
			sum[i+1]=sum[i]+a[i];
		}
		for(int i=0;i<n;i++){//start
			for(int j=i;j<n;j++){//end
				int tmp=sum[j+1]-sum[i];
				m=max(m,tmp);
				if(tmp<=0){i=j;break;}
				//printf("%d-%d:%d\n",i,j,tmp);
			}
		}
		cout<<m<<endl;
	}
    return 0;
}

C++: //640711C ???????????¬????????°???
//?????????????????????:Maximum Sum Sequence
//????????????????????????15?????????????????°5??????
//

#include <algorithm>
#include <iostream>
using namespace std;

int n,s[5000+10];

int biggest(int n){
    int M=-200000-10;
    for(int p=0;p<n;p++){
//        cout << "s[" << p << "] = " << s[p] << endl;
        if(s[p]>M) M=s[p];
        for(int q=0;q<p;q++){
//            cout << "s[" << p << "]-s[" << q << "] = " << s[p]-s[q] << endl;
            if(s[p]-s[q]>M) M=s[p]-s[q];
        }
    }
    return M;
}

int main(){
    int n;
    while(cin){
        cin >> n;
        if(n==0) break;
        int a[5000+10];
        for(int i=0;i<n;i++){
            cin >> a[i];
            if(i==0) s[i]=a[i];
            else s[i]=s[i-1]+a[i];
        }
        cout << biggest(n) << endl;
    }
}

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

using i64 = long long int;

i64 acc[5003]={0};

int main(){
    int n;
    while(cin >> n, n != 0){
        vector<i64> v;
        for(int i=0;i<n;++i){
            i64 a;
            cin >> a;
            v.push_back(a);
        }
        for(int i=0;i<n;++i){
            acc[i+1] = acc[i] + v[i];
        }

        i64 ans = LLONG_MIN;
        for(int i=1;i<=n;++i){
            for(int j=i;j<=n;++j){
                ans = max(ans, acc[j] - acc[i-1]);
            }
        }

        cout << ans << endl;
    }

    return 0;
}

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

int main(void)
{
    ios::sync_with_stdio(false);
    while(1) {
        int n;
        int a[5001] = {0};
        long int ans = -10000000;
        cin >> n;
        if(n == 0) break;

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

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

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int box[5001];
	int i,j;
	int sum;
	int MAX;
	while(1){
		cin>>n;
		if(n==0)	break;
		for(i=0;i<n;i++)	cin>>box[i];
		MAX=INT_MIN;
		for(i=0;i<n;i++){
			sum=box[i];
			//cout<<sum<<endl;
			MAX=max(MAX,sum);
			for(j=i+1;j<n;j++){
				sum+=box[j];
			//	cout<<sum<<endl;
				MAX=max(MAX,sum);
			}
		}
		cout<<MAX<<endl;
	}
	return 0;
}