Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

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

using std::cin;

int main()
{

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

        std::vector<int> line(n);
        for (auto i = 0; i < n; i++) {
            int in;
            cin >> in;
            line.push_back(in);
        }

        int max = -100000;
        for (auto i = 0; i < n; i++) {
            int sum_ij;
            int max_i;
            max_i = sum_ij = line.at(i);
            for (auto j = i + 1; j < n; j++) {
                sum_ij += line.at(j);
                if (sum_ij > max_i) {
                    max_i = sum_ij;
                }
            }
            if (max_i > max) {
                max = max_i;
            }
        }

        std::cout << max << std::endl;
    }

    return 0;
}

C++: #include<stdio.h>

int main(){
	int n,a[5000],i,j,k,wa,max;
	
	while(0<=scanf("%d",&n)){
		if(n==0)break;
		max=0;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				wa=0;
				for(k=i;k<=j;k++){
					wa+=a[k];
				}
				if(max<wa)max=wa;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

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);
    }
}