Go: package main

import (
        "fmt"
)

func main() {
        for {
                var n int
                _, err := fmt.Scanf("%d", &n)
                if err != nil || n == 0 {
                        break
                }

                var sum [5001]int

                for i := 1; i <= n; i++ {
                        fmt.Scanf("%d", &(sum[i]))
                        if i > 1 {
                                sum[i] += sum[i-1]
                        }
                }

                max_sum := sum[1]
                for i := 1; i <= n; i++ {
                        for j := 0; j < i; j++ {
                                if max_sum < sum[i] - sum[j] {
                                        max_sum = sum[i] - sum[j]
                                }
                        }
                }
                fmt.Printf("%d\n", max_sum)
        }
}

C++: #include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
using namespace std;
typedef long long llong;
typedef vector <llong> vll;

int maxv(vll &x){
	llong tmp=x[0];
	for (int i=1; i<x.size(); i++)
		if (x[i]>tmp) tmp=x[i];
	return tmp;
}

int main(void){
	int n;
	vll x;
	while (cin>>n, n!=0){
		int s=LLONG_MIN;
		for (int i=0; i<n; i++){
			int n2;
			cin>>n2;

			for (int j=0; j<x.size(); j++){
				x[j] += n2;
			}
			x.push_back(n2);
			s=max(s, maxv(x));
		}
		cout<<s<<endl;
		x.clear();
	}
	return 0;
}

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

int main(){
	int n;
	while(cin >> n, n){
		//n++;
		vector<int> dp(n), vec(n);
		//t[0] = 0;
		/*for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}*/
		for(int i=0;i<N;i++)cin >> vec[i];
		dp[0]=vec[0];
		for(int i=1;i<N;i++)dp[i]=max(dp[i-1]+vec[i],vec[i]);
		cout << *max_element(t.begin(), t.end()) << endl;
	}
	return 0; 
}

/*
7
-5
-1
6
4
9
-6
-7
*/

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

int main(){
int n,m=0;
int a[5001];
int sum;
int big=0;
while(cin>>n){
big=0;
for(int i=0;i<n;i++)cin>>a[i];

for(int i=0;i<n-1;i++){
if((a[i]>=0&&a[i+1]>=0)||(a[i]<=0&&a[i+1]<=0)){
a[i]+=a[i+1];
for(int j=i+1;j<n-1;j++)a[j]=a[j+1];
i--;
n--;}}

for(int i=1;i<n+1;i++){
for(int j=0;j<n-i+1;j++){
sum=0;
for(int k=0;k<i;k++){
sum+=a[j+k];}
if(sum>big){big=sum;}}}
cout<<big<<endl;}}

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

using namespace std;

int main(){
	int n,sumax,temp;
	int num[5000];
	
	while(scanf("%d",&n)){
		if(n==0)
		break;
		for(int i=0;i<n;i++){
			scanf("%d",&num[i]);
		}
		sumax = 0;
		for(int i=0;i<n;i++){
			if(num[i]>sumax)
			sumax = num[i];
			temp = num[i];
			for(int j=i+1;j<n;j++){
				temp+=num[j];
				if(temp>sumax)
				sumax=temp;
			}
		}
		printf("%d\n",sumax);
	}
}

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int mod=1000000007;
    int n;
    for (;;) {
        scanf("%d",&n);
        if (n!=0) {
            vector<int> p(n);
            for (auto&e:p) {
                scanf("%d",&e);
            }
            int ans=p[0];
            for (int i=0;i<n;i++) {
                int tmp=0;
                for (int j=i;j<n;j++) {
                    tmp+=p[j];
                    ans=max(ans,tmp);
                }
            }
        } else {
            break;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int Merge(vector<int>& A, int p)
{
	while (p > 1 && A[p] > 0){
		int a = A[p - 2] + A[p - 1] + A[p];
		if (a > A[p - 2] && a > A[p]){
			A[p - 2] += A[p - 1] + A[p];
			A[p - 1] = A[p] = 0;
			p -= 2;
		}
		else break;
	}
	return p;
}
int main()
{
	int n, k, p, m;
	bool isPlus = true;
	while (cin >> n){
		if (0 == n) break;
		vector<int> A(n, 0);
		m = INT_MIN;
		p = 0;
		for (int i = 0; i < n; ++i){
			cin >> k;
			if (m < k) m = k;
			if (0 == i){
				A[p] = k;
				isPlus = (k > 0);
			}
			else {
				if (isPlus == (k > 0)){
					A[p] += k;
				}
				else{
					if (isPlus){
						p = Merge(A, p);
						if (m < A[p]) m = A[p];
					}
					++p;
					A[p] = k;
					isPlus = !isPlus;
				}
			}
		}
		p = Merge(A, p);
		if (m < A[p]) m = A[p];
		cout << m << "\n";
	}
	return 0;
}

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

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)  return 0;
        int result = INT_MIN/2;
        int tmp = INT_MIN/2;
        for(int i=0; i<n; ++i){
            int a;
            cin >> a;
            tmp = max(tmp + a, a);
            result = max(result, tmp);
        }
        cout << result << endl;
    }
}

C++: // start 20:09
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

#define REP(i, n) for ( int i = 0; i < n; i++ )

using namespace std;

int sum(vector<int> &nums, int oft, int len) {
    int ret = 0;
    for ( int i = oft; i < len; i++ ) {
        ret += nums[oft+i];
    }
    return ret;
}

int main() {
    int n;
    
    while(cin >> n, n) {
        int max_n;
        vector<int> nums(n);

        REP(i, n) cin >> nums[i];
        
        max_n = nums[0];

        REP(oft, n) for( int len = 1; len <= n-oft; len++ ) {
            // cout << oft << " " << len << endl;
            max_n = max(max_n, sum(nums, oft, len));
        }
        cout << max_n << 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;
    }

    cout << maxu << endl;

  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#define INT_MIN 2147483648

using namespace std;

int main(void){
	int *a,maxi;
	for(int n;cin >> n,n;){
		maxi = INT_MIN;
		a = new int[n];
		for(int i=0;i<n;i++)
			cin >> a[i];

		for(int i=0;i<n;i++)
			for(int j=i,sum=0;j<n;j++)
				maxi=max(maxi,sum+=a[j]);
		delete [] a;

		cout << maxi << endl;
	}
	return 0;
}

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

int main(){
    int n;
    while(scanf("%d",&n) && n != 0){
        int arr[n];
        for(int i = 0; i < n; i++){
            scanf("%d",&arr[i]);
        }
        int max_e = 0, max_s = 0;
        for(int cur = 0; cur < n; cur++){
            max_e = max(arr[cur], max_e + arr[cur]);    //max_e????????????????????´??????arr[cur]???max_e?????£??\?????????
            max_s = max(max_s, max_e);
        }
        printf("%d\n",max_s);
    }
}

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

using namespace std;

int findMax(vector<int>& a) {
  int r = 0, sum, max;
  for (int i = 0, max = 0; i < a.size(); i++) {
    for (int j = i, sum = 0; j < a.size(); j++) {
      sum += a[j];
      if (max < sum) max = sum;
    }
    if (max > r) r = max;
  }
  return r;
}

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

    vector<int> a;
    for (int i = 0; i < n; i++) {
      cin >> t;
      a.push_back(t);
    }
    cout << findMax(a) << endl;
  }
  return 0;
}