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 <bits/stdc++.h>

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) REP (i, 0, n)
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double EPS = 1e-8;

int main() {
	int n;
	while (cin >> n, n) {
		int a[n], ans = -10000000;
		rep (i, n) cin >> a[i];
		int dp[n];
		dp[0] = a[0];
		REP (i, 1, n) {
			dp[i] = max(dp[i - 1] + a[i], a[i]);
		}
		rep(i, n) {
			ans = max(ans, dp[i]);
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<numeric>
#include<functional>
using namespace std;
int main(){
	int n;
	while(cin >> n){
		if(n==0) break;
		vector<int> a;
		vector<int> s;
		int sum=0;
		for(int i=0;i<n;++i){
			int t;
			cin >> t;
			a.push_back(t);
		}
		for(int i=0;i<a.size();++i){
			for(int j=i+1;j<=a.size();++j){
				s.push_back(accumulate(a.begin()+i,a.begin()+j,0));
			}
		}
		stable_sort(s.begin(),s.end(),greater<int>());
		cout << s[0] << endl;
	}
	return 0;
}

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

int main(){
  int n;
  long int a[5010];
  long int s[5010];
  while(cin>>n && n){
    long int mx=0;
    for( int i=1;i<=n;i++ ){
      cin >> a[i];
      mx = max(mx, a[i]);
    }
    for( int i=1;i<=n;i++ ){
      s[i] = a[i];
      for( int j=i+1;j<=n;j++ ){
	s[j] = s[j-1] + a[j];
	mx = max(mx, s[j]);
      }
    }

    cout << mx << endl;
  }
  return 0;
}

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

int main(){
  int n, max_, tmp, a;
  while(cin >> n){
    max_ = 0; tmp=0;
    for(int i=0; i<n; i++){
      cin >> a;
      tmp = max(0,tmp+a);
      max_ = max(tmp,max_);
    }
    cout << max_ << endl;
  }
  return 0;
}

C++: #include <stdio.h>
int main()
{
	int n,a[5000];
	while(1){
		int max=-10001;
		scanf("%d",&n);
		if(n==0)
			break;
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				if(max<sum)
					max=sum;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

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

typedef long long ll;

ll a[5001];

int main() {
  int num;
  while( cin >> num, num ) {
    ll maxn = -1000000000;
    for ( int i = 0; i < num; i++ ) cin >> a[i];
    for ( int i = 0; i < num; i++ ) {
      ll sum = 0;
      for ( int j = i; j < num; j++ ) {
	sum += a[j];
	maxn = max(maxn,sum);
      }
    }
    cout << maxn << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000],saidai=0;
	cin>>n;
	while(n!=0){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;n<i;i++){
			for(int x=n;x>=i;x--){
				int kazu=0;
				for(int y=x;y>=i;y--){
					kazu=kazu+a[y];
				}
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
	}
	cout<<saidai<<endl;
}

C++: #include <cstring>

int a[5001];
int b[5001];
int c[5001];
int d[5001];

int main()
{
    memset(a, 0, 5001);
    memset(b, 0, 5001);
    memset(c, 0, 5001);
    memset(d, 0, 5001);
    return 0;
}

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

int main() {
	int n;
	while (std::cin >> n) {
		if (n == 0) break;
		std::vector<int> a;
		int max = 0, left = 0, right = 0, lmin = 0, rmin = 0;
		for (int i = 0; i < n; ++i) {
			int ai;
			std::cin >> ai;
			a.push_back(ai);
			max += ai;
		}
		// ここをかく
		int lmax,rmax;
		std::vector<int>::iterator leftend = a.begin();
		std::vector<int>::reverse_iterator rightend = a.rbegin();
		for (std::vector<int>::iterator itr = a.begin(); itr != a.end(); ++itr) {
			left += *itr;
			if (left < lmin) {
				lmin = left;
				leftend = itr;
			}
		}
		for (std::vector<int>::iterator itr = a.end() - 1; itr != leftend; --itr) {
			right += *itr;
			if (right < rmin) {
				rmin = right;
			}
		}
		lmax = max - lmin - rmin;
		left = 0; right = 0; lmin = 0; rmin = 0;
		for (std::vector<int>::reverse_iterator ritr = a.rbegin(); ritr != a.rend(); ++ritr) {
			right += *ritr;
			if (right < rmin) {
				rmin = right;
				rightend = ritr;
			}
		}
		for (std::vector<int>::reverse_iterator ritr = a.rend() - 1; ritr != rightend; --ritr) {
			left += *ritr;
			if (left < lmin) {
				lmin = left;
			}
		}
		rmax = max - lmin - rmin;
		max = lmax > rmax ? lmax : rmax;

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

	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int num[5001];
/*
int sum(int a,int b){
  int s=0;
  for(int i=0;i<b;i++){
    s+=num[a+i];
  }
  return s;
}
*/
int main(){
  int max;
  int n,sum;
  
  while(cin>>n,n){
    max=-10000000;
    // int sum=-10000000;
    for(int i=0;i<n;i++){
      cin>>num[i];
    }
    for(int i=0;i<n;i++){
      sum=0;
      for(int j=i;j<n;j++){
	sum+=num[j];
	if(max<sum)max=sum;
      }
    }
    cout<<max<<endl;
  }
}

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

int main()
{
	int n;
	while (cin >> n, n)
	{
		int ary[5001] = {};

		for (int i = 1; i <= n; i++)
		{
			cin >> ary[i];
		}
		for (int i = 1; i <= n; i++)
		{
			ary[i] += ary[i - 1];
		}

		int ans = -1;
		for (int i = 0; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				ans = max(ans, ary[j] - ary[i]);
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

int main(){
	long long a, maximum;
	int n;
	while (cin >> n, n){
		maximum = -1000000;
		long long S[5010] = {};
		for (int i = 1; i <= n; i++){
			cin >> a;
			S[i] = S[i - 1] + a;
		}

		for (int i = 0; i <= n; i++)
			for (int j = i + 1; j <= n; j++){
				maximum = max(maximum, S[j] - S[i]);
			}
		cout << maximum << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int a[5001];
int main(){
    int n;
    while(cin >> n && n){
        rep(i, n) cin >> a[i];
        int ans = -INF;
        REP(i, 0, n){
            int sum = a[i];
            ans = max(ans, sum);
            REP(j, i + 1, n){
                sum += a[j];
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include<stdio.h>
int main(){
	int a;
	while(1){
		scanf("%d",&a);
		if(a==0)return 0;
		int n[5000];
		for(int i=0;i<a;i++)scanf("%d",n+i);
		int dp[5000];
		dp[0]=n[0];
		int max=0;
		for(int i=1;i<a;i++){
			if(dp[i-1]>0)dp[i]=dp[i-1]+n[i];
			else dp[i]=n[i];
			if(max<dp[i])max=dp[i];
		}
		printf("%d\n",max);
	}
}

C++: #include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
if(n==0)
{
	break;
}
else
{
int a[n];
int A=0;
int R=-100000;
for(h=0;h<n;h++)
{
	cin>>a[h];
}
for(int i=0;i<n;i++)
{
	for(int j=0;j<n-i;j++)
	{
	for(int k=i;k<=j;k++)
	{
		A=A+a[k]
		
	}	
	if(R<A)
	{
		R=A;
	}
	A=0
	}
}
cout<<R<<endl;
}
return 0;
}

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

int main()
{
	int n, a[5000], i, j, k, l, sum, max;

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

		for (i = 0; i < n; i++)
			cin >> a[i];

		max = -500000000;
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n - i; j++)
			{
				for (k = 0; k < n - i; k++)
				{
					sum = 0;
					for (l = k; l <= i; l++)
						sum += a[l];
					if (sum > max) max = sum;
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}