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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

int main(int argc, char const *argv[]) {
  int i,j;

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

    std::vector<long> a(n+1);
    rep(i,n) scanf(" %ld", &a[i+1]);

    std::vector<long> sum(n); //a[1]~a[i]??????
    sum[0]=0;
    for(i=1; i<=n; ++i) sum[i]=sum[i-1]+a[i];

    long ans=-5000*100000-1;
    for(i=1; i<=n; ++i){
      for(j=i; j<=n; ++j){
        ans=max(ans,sum[j]-sum[i-1]);
      }
    }

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

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	int a[5000];
	while (cin >> n&&n != 0) {
	
			int sum2 = -10001;
		for (int i = 0; i<n; i++)
			cin >> a[i];
		int sum3 = -100000;
		int sum = -10001;
		for (int i = 0; i<n; i++) {
			if(a[i] < 0) goto yo;
			for (int j = 0; j <= i; j++) {
				if (a[j]<0||(j>=1&&a[j-1]<0&&(a[j-1]+a[j])<0)) goto stop;;
				sum2 = 0;
				for (int z = j; z <= i; z++) {
					sum2 += a[z];
					if (sum < sum2) {
						sum = sum2; 
					}
				}
			stop:;
			}
		yo:;
			if (sum < a[i]) sum = a[i];
			if (sum3<sum) sum3 = sum;
		}
		cout << sum3 << endl;
	}
}

C++: #include<cstdio>
#include<algorithm>

using namespace std;
int n,a[5008];

int solve(){
  int res=0;
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      int tmp=0;
      for(int p=i;p<=j;p++){
        tmp+=a[p];
      }
      res=max(res,tmp);
    }
  }
  return res;
}

int main(){
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
    }

    printf("%d\n",solve());

  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
	long long int n,ans = 0;
	while(1){
		cin >> n;
		if(n == 0)break;

		long int a[n];

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

C++: #include <cstdio>

int ns[5001];

int max(int a,int b){return a>b?a:b;}

int main(){
  int n;
  while(scanf("%d",&n),n){
    for(int i=1; i<=n; i++)
      scanf("%d",&ns[i]);
    for(int i=2; i<=n; i++)
      ns[i]+=ns[i-1];

    int ans=-100001;
    for(int i=0; i<=n; i++)
      for(int j=0; j<i; j++)
	ans=max(ans,ns[i]-ns[j]);

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

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        int ans[5050] = {0};
        for(int i = 0; i < n; i++){
            scanf("%d",&ans[i]);
        }
        long long int mx = -300000000;
        for(int i = 0; i < n; i++){
            long long int sum = 0;
            for(int j = i; j < n; j++){
                sum += ans[j];
                if(sum > mx) mx = sum;
            }
        }
        printf("%lld\n",mx);
    }
	return 0;
}

C++: #include <stdio.h>

int main() {
        int n, a;

        while (true) {
                scanf("%d", &n);
                if (!n) {
                        break;
                }

                long long sum = 0, max = -100000;
                for (int i = 0; i < n; i++) {
                        scanf("%d", &a);
                        sum += a;
                        if (sum > max) {
                                max = sum;
                        }
                        if (sum < 0) {
                                sum = 0;
                        }
                }
                printf("%lld\n", max);
        }

        return 0;
}

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

int main(){
    int n;
    cin>>n;
    while(n!=0){
        vector<int> a(n);
        for(int i=0;i<n;i++) cin>>a[i];
        vector<int> S(n+1);
        for(int i=0;i<=n;i++){
            S[i] = S[i-1] + a[i-1];
        }

        int ans =0;
        int sum =0;

        for(int i=n;i>0;i--){
            for(int j=0;j<n;j++){
                int tmp=S[i] - S[j];
                if(ans<tmp){
                    ans = tmp;
                }
            }
        }
        cout<<ans<<endl;
        cin>>n;
    }
    return 0;
}

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

using namespace std;

int main(void){

  while(1){

    int n;
    cin >> n;
    if( n == 0 ) break;
    
    int N[5000];
    for( int i = 0 ; i < n ; i++ ){
      cin >> N[i];
    }
   
    int sum = 0;
    int l = -9999999;
    for( int i = 0 ; i < n ; i++ ){
      if( sum + N[i] >= N[i] ){
	sum += N[i];
      }
      if( sum > l ){
	l = sum;
      }
    } 
    cout << l << endl;
  }
  return 0;
}

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

int main(){

  int n,count,maxu;

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

    int numbers[n];
    for(int i=0;i<n;i++)
      cin >> numbers[i];
    maxu = count = 0;

    for(int i=0;i<n;i++){
      count += numbers[i];
      maxu = max(count,maxu);
      if(count<0)
	count = 0;
    }
    if(count>0)
      maxu = max(count,maxu);

    cout << maxu << endl;

  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main( void )
{
	while (1)
	{
		int n;
		cin >> n;
		if ( n == 0 )
			break;

		int max_value = 0;
		int now = 0;
		for ( int i = 0; i < n; i++ )
		{
			int value;
			cin >> value;
			now += value;
			max_value = max( now, max_value );
			if ( now < 0 )
				now = 0;
		}

		if ( now > 0 )
			max_value = max( now, max_value );

		cout << max_value << endl;

	}
	return 0;
}

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

int main(){

    while(1){
    int n; cin >> n;
    if(!n) break;
    vector<int> a(n);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(i > 0) a[i] += a[i - 1];
    }
    a[0] = 0;
    int ans = a[1];
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j <= n; j++){
            ans = max(ans, a[j] - a[i]);
        }
    }

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

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

int main() {
    int n,ans;
    cin >> n;
    while(n!=0){
        int a[5001];
        for(int i=0;i<n;++i){
            cin >> a[i];
        }
        ans=a[1]+a[0];
        for(int i=0;i<n-2;++i){
            ans=max(ans,a[i+2]+a[i+1]);
        }
        cout << ans << endl;
        cin >> n;
    }
}
7
-5
-1
6
4
9
-6
-7
13
1
2
3
2
-2
-1
1
2
3
2
1
-2
1
3
1000
-200
201
0