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 <cstdio>
using namespace std;


int main()
{
    int sum;
    int currentSum;
	int loop;
	int a[5005];

	while (cin >> loop, loop) {
	    // O(n)
	    for(int i=0; i<loop; i++){
	        cin >> a[i];
	    }
	    
	    // O(n^2)
	    sum=0, currentSum=0;
	    for(int j=0; j<loop; j++){
	        for(int k=j; k<loop; k++){
	            //cout << "k : " << k << endl;
	            currentSum += a[k];
	            if(currentSum > sum){
	                sum = currentSum;
	            }
	        }
	        currentSum = 0;
	    }
        cout << sum << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<cfloat>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

#define PI (3.1415926535)
#define EPS (1e-10)

int main(){
  int n;
  while(cin>>n,n){
    vector<int> a(n);
    vector<int> s(n+1);
    int ans = INT_MIN;
    REP(i,n){
      cin>>a[i];
      s[i+1] = s[i];
      s[i+1] += a[i];
    }
    REP(i,n) for(int j=i+1; j<=n; j++){
      ans = max(ans, s[j]-s[i]);
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	int n;
	int a;
	int sum;
	int sum2;
	int max;
	cin >> n;
	while(n){
		cin >> sum;
		max = 0;
		for(int i=0;i<n-1;i++){
			cin >> sum2;
			sum += sum2;
			if(sum < sum2){
				sum = sum2;
			}
			if(sum > max){
				max = sum;
			}
		}
		cout << max << endl;
		cin >> n;
	}
	return 0;
}

C++: //#define _USE_MATH_DEFINES
//#include <cmath>
#include <iostream>
//#include <stdio.h>
//#include <stdlib.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <time.h>
//#include <sstream>
//#include <queue>

using namespace std;


int main(){

	int n, buf;
	long long ans, sum;
	vector <int> p;


	while (1){
		p.clear();
		sum = 0;
		ans = -100000;

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

		for (int i = 0; i < n; i++){
			cin >> buf;
			p.push_back(buf);
		}

		for (int left = 0; left < n; left++){
			for (int right = left; right < n; right++){
				for (int i = left; i <= right; i++){
					sum += p[i];
				}
				if (sum > ans) ans = sum;
				sum = 0;
			}
		}

		cout << ans << endl;

	}

	return 0;
}

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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n = 0;
	std::vector<int> a;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif

	for(;;){
#if INPUT_FROM_FILE
		ifs >> n;
#else
		std::cin >> n;
#endif
		if(n == 0){ break; }

		a.resize(n);
		for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
			ifs >> a[i];
#else
			std::cin >> a[i];
#endif
		}

		long max_sum = -1000000000;

		for(int i = 0; i < n; i++){
			long sum = a[i];
			if(max_sum < sum){
				max_sum = sum;
			}
			for(int j = i + 1; j < n; j++){
				sum += a[j];
				if(max_sum < sum){
					max_sum = sum;
				}
			}
		}

		std::cout << max_sum << std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
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{
					++p;
					A[p] = k;
					isPlus = !isPlus;
				}
			}
		}
		vector<int> B(p + 1, 0);
		vector<int> C(p + 1, 0);
		for (int i = 0; i <= p; ++i){
			if (0 == i)
				C[0] = B[0] = A[0];
			else{
				int s = B[i - 1];
				for (int j = 0; j <= i; ++j){
					C[j] += A[i];
					if (s < C[j]) s = C[j];
				}
				B[i] = s;
			}
		}
		if (m < B[p]) m = B[p];
		cout << m << "\n";
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    int s, m = 0, r;
    cin >> r;
    s = r;
    for (int i = 1; i < n; i++) {
      int x;
      cin >> x;
      s += x;
      if (s < m)
        m = s;
      else
        r = max(r, s-m);
    }
    cout << r << endl;
  }
}

C++: #include <cstdio>
int main(){int n,i,j,s,m,a[5000];while(scanf("%d", &n)&&n){for(i=0;i<n;i++)scanf("%d",&a[i]);m=-2147483647;for(i=0;i<n;i++,s=0)for(j=i;j<n;j++)if((s+=a[j])>m)m=s;printf("%d\n",m);}}

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

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<long long int> hyou(n+1, 0);
		long long int a;
		long long int MAX = 0;
		int maxn = 0;
		for (int i = 0; i < n; i++) {
			cin >> a;
			hyou[i+1] = hyou[i] + a;
			if (i == 0) {
				MAX = hyou[1];
			}
		}
		for (int i = 2; i <= n; i++) {
			MAX = max(MAX, hyou[i]);
			for (int j = 1; j < i; j++) {
				if (hyou[j] < 0) {
					MAX = max(MAX, hyou[i]-hyou[j]);
				}
			}
		}
		cout << MAX << endl;
	}
	return 0;
}

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

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

         int a;
         int max = numeric_limits<int>::min();
         int sum = numeric_limits<int>::min();
         for(int i=0; i<n; i++){
             cin >> a;

             if( max<0 && a<0 && max<a ) { max = a; continue; }
             else if( max<0 && a<0 && max>a){ continue; }

             if( a>0 ){
                 if( sum<0 ) sum = a;
                 else sum += a;
             }else{
                 if( sum+a>0 ) sum += a;
                 else sum = a;
             }
             if( sum > max ) max = sum;
         }
         cout << max << endl;
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
while (1){
long n,dset[5000],temp=0,max;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
max=-99999;
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                if (max<temp){
                        max=temp;
                }
        }
temp=0;
}
cout<<max<<endl;
}
return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>

typedef long long ll;
using namespace std;

int main()
{
	int T;
	int maxS=numeric_limits<int>::min();
	while(~scanf("%d",&T)){
		int* dp = new int[T+1]();
		if(T==0) break;
		for(int t=0;t<T;t++){
			int tmp;
			scanf("%d",&tmp);
			dp[t+1] = max(dp[t] + tmp,tmp);
			//printf("dp[%d+1] = %d,dp[%d] = %d\n",t,dp[t+1],t,dp[t]);
		}

		sort(dp,dp+T+1,greater<int>());
		cout << dp[0] << endl;

		delete[] dp;
	}
}

C++: #include <stdio.h>

int main(void)
{
	int i;
	int max;
	int 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 (max < total){
				max = total;
			}
			if (total < 0){
				total = 0;
			}
		}
		printf("%d\n", max);
	}
	return (0);
}