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 <cstdlib>
#include <climits>
using namespace std;
const static int L_MAX = 5001;

int main() {
  while( 1 ) {
    int n;
    cin >> n;
    if( !n ) { return EXIT_SUCCESS; }

    int seq[ L_MAX ];
    int sum[ L_MAX ];
    int maxv = INT_MIN;
    int minvInSum = 0;
    seq[ 0 ] = 0;
    sum[ 0 ] = 0;

    for( int i = 1; i <= n; i++ ) {
      cin >> seq[ i ];
      sum[ i ] = sum[ i - 1 ] + seq[ i ];
      minvInSum = min( minvInSum, sum[ i ] );
      maxv = max( maxv, sum[ i ] - minvInSum );
    }
    cout << maxv << endl;
  }
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi array(n+1);
		array[0] = 0;
		reep(i, 1, n+1){
			scanf("%d", &array[i]);
			array[i] += array[i-1];
		}

		int ans = INT_MIN;
		rep(i, n){
			reep(j, i+1, n+1)
				ans = max(ans, array[j]-array[i]);
		}

		printf("%d\n", ans);
	}

	return 0;
}

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

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

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

int main() {
	int n;
    while(1){
        cin>>n;
        if(!n)break;

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

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

int64_t a[5000];
int64_t dp[2][5000];

int64_t solve(int n){
  int64_t summax=INT64_MIN;
  for(int i=0;i<n;i++){
    summax = (summax < a[i])?a[i]:summax;
  }

  for(int i=1;i<n;i++){
    for(int j=0;j<n-i;j++){
      dp[i%2][j] = dp[(i-1)%2][j] + a[i+j];

      summax = (summax < dp[i%2][j])?dp[i%2][j]:summax;
    }
  }
  return summax;
}

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

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

    cout << solve(n) << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int a[5000];
	int left[5000], right[5000];
	int n;
	
	while (true) {
		cin >> n;
		if (n==0) break;
		
		bool existsPos = false;
		for (int i=0; i<n; i++) {
			cin >> a[i];
			if (a[i] > 0) existsPos = true;
		}
		
		int maximum;
		
		if (existsPos) {
			int left_max = a[0];
			int left_max_pos = 0;
			left[0] = a[0];
			for (int i=1; i<n; i++) {
				left[i] = left[i-1] + a[i];
				if (left[i] > left_max) {
					left_max = left[i]; left_max_pos = i;
				}
			}
			int right_max = a[n-1];
			int right_max_pos = n-1;
			right[n-1] = a[n-1];
			for (int i=n-2; i>=0; i--) {
				right[i] = right[i+1] + a[i];
				if (right[i] > right_max) {
					right_max = right[i]; right_max_pos = i;
				}
			}
			
			maximum = 0;
			for (int i = right_max_pos; i <= left_max_pos; i++) maximum += a[i];
		}
		else {
			maximum = -100000;
			for (int i=0; i<n; i++) {
				if (a[i] > maximum) maximum = a[i];
			}
		}
		
		cout << maximum << endl;
	}
		
	return 0;
}

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

int main()
{
	int n;
	while(cin>>n){
		if(n==0) break;
		int a[n], S[n], sum=0;
		for(int i=0;i<n;++i){
			cin>>a[i];
			sum+=a[i];
			S[i]=sum;
		}

		long max=S[0];
		for(int i=0;i<n;++i){
			if(S[i]>max) max=S[i];
			for(int j=0;j<i+1;++j){
				if(S[i]-S[j]>max) max=S[i]-S[j];
			}
		}

		cout<<max<<endl;
	}

	return 0;

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

vector<long long> num;
long long dp[5000];

void init(){
  for(int i = 0; i < 5000; i++){
    dp[i] = 0;
  }
  num.clear();
}

int main(void){
  while(true){
    long long maximum = 0, n;
    cin >> n;
    if(!n)  break;
    init();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < n; i++){
      dp[i] = max(dp[i-1] + num[i], num[i]);
    }
    
    for(int i = 0; i < n; i++){
      if(dp[i] > maximum) maximum = dp[i];
    }

    cout << maximum << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int stage[100000] = {0};
        for(int i = 1;i <= n; i++){
            scanf("%d",&stage[i]);
        }
        int x = 0;
        int ans = -1000000;
        for(int i = 1;i <= n; i++){
            for(int j = i;j <= n; j++){
                x += stage[j];
                ans = max(ans,x);
            }
            x = 0;
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

template<typename T>
T m(T a, T b) { return a > b ? a : b; }

int main(void) {
    freopen("i.in", "r", stdin);
    int N;
    while(true) {
        cin >> N;
        if(N == 0) break;
        vector<int> v(N);

        for(int i = 0; i < N; i++) cin >> v[i];

        long long mx = -100000L;

        for(int i = 0; i < N; i++) {
            long long tmp = 0L;
            for(int j = i; j < N; j++) {
                tmp += v[j];
                mx = m(mx, tmp);
            }
        }
        cout << mx << endl;
    }
    return 0;
}

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

int main(){
	int n;
	int a;
	int sum;
	cin >> n;
	while(n){
		cin >> sum;
		for(int i=0;i<n;i++){
			cin >> a;
			if(sum < a){
				sum = a;
			}else{
				sum += a;
			}
		}
		cin >> n;
	}
	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 (total < 0){
				total = 0;
			}
			if (max < total){
				max = total;
			}
		}
		printf("%d\n", max);
	}
	return (0);
}

C++: #include <iostream>

using namespace std;

int main(void){
	int n;
	long long int a[5000]={0};
	while(cin >> n){
		long long int max = 0;
		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;
}