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 <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;

int main(){
	int N;
	int x;
	vl sum(5001);
	while(1){cin>>N;if(N==0) break;int index=0;
		ll ans = INT_MIN;
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-2]);
			}
		}
		cout<< ans <<endl;
	}
}

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

void saiki(int num,int sum);

int term[10000],n,ans;

int main(void)
{
   while(scanf("%d",&n))
   {
      ans = 0;
      if(n == 0) break;
      for(int i = 0;i < n;i++) scanf("%d",&term[i]);
      for(int i = 0;i < n;i++) saiki(i,0);

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

void saiki(int num,int sum)
{
   if(num > n) return;
   saiki(num+1,sum+term[num]);
   if(ans < sum) ans = sum;
}

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

int main(){
  int n,a[5000];

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

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

int max(int a, int b)
{
  return (a>b)? a : b ;
}
int main()
{
 int n, x, y, a[5001];
 while(cin>>n, n)
 {
  for(int i=0; i<n; i++)
  {
   cin>>a[i];
   }
  x=a[0];
 for(int i=0; i<n; i++)
 {
  int sum=0;
  for(int j=i; j<n; j++)
   {
    sum += a[j];
     x = max( x, sum );
    }
   }
  cout<<x<<endl; 
 }
 }

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

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

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(){
	int n,num[5010],hoge,ans;
	while(cin>>n,n!=0){
	hoge=0;
	for(int i=0;i<n;i++)cin>>num[i];
	ans=num[0];
	for(int i=0;i<n;i++){
		hoge=0;
		for(int j=i;j<n;j++){
			hoge+=num[j];
			ans=max(ans,hoge);
		}
	}
		cout<<ans<<endl;
	}
}

C++: //AOJ022
#include <stdio.h>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
	int n,i,num[5000];
	long long int sum[5001];
	while(1){
		sum[0] = 0ll;
		scanf("%d",&n);
		if(!n) break;
		for(i = 0;i < n;i++){
			scanf("%d",&num[i]);
			sum[i + 1] = sum[i] + num[i];
		}
		sort(sum,sum + n + 1,greater<long long>());
		printf("%lld\n",sum[0] - sum[n]);
	}
	return 0;
}

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

int main()
{
  int n, a[5000], ca;
  long long ans, sum;
  while(cin >> n, n){
    for (int i = 0; i < n; i++){
      cin >> a[i];
    }

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

  return 0;
}

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

int main () {

int n = -1, max = 0, cum = 0;


cin >> n;


    while (n) {

    int foo[5000];

    for (int i = 0; i < n; i++) {

        cin >> foo [i];

        if (i == 0)
            max = foo [i];

        cum += foo[i];

        if (cum < 0)
            cum = 0;

        if (cum > max && cum > 0)
            max = cum;

        }

    cout << max << endl;

    max = 0;
    cum = 0;

    cin >> n;

    }



    return 0;

}

C++: #include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;



int main()
{
	int n;
	while (cin >> n && n > 0)
	{
		vector<int> a = vector<int>(n);
		for (int i = 0; i < n; i++)
			cin >> a[i];

		vector<int> s = vector<int>(1, 0);
		bool f = true;
		bool plus = false;
		for (int i = 0; i < n; i++)
		{
			if (a[i] >= 0)
			{
				if (!f)
					f = true;
				if (!plus)
					plus = true;
				s[0] += a[i];
			}
			else if(s[0] > a[i])
			{
				if (f)
				{
					s.push_back(s[0]);
					f = false;
				}
				s[0] += a[i];
			}
			else
			{
				s[0] = 0;
			}

		}
		if (!plus)
		{
			int max = a[0];
			for (int i = 1; i < n; i++)
			{
				if (max < a[i])
					max = a[i];
			}
			cout << max << endl;
			continue;
		}
		for (int i = 1; i < s.size(); i++)
		{
			if (s[i] > s[0])
				s[0] = s[i];
		}
		cout << s[0] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>

typedef long long Int;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
using namespace std;

Int aa[10000];
Int dp[10000];


int main(){
	int n;
	while (cin >> n, n){

		REP(i, n){
			cin >> aa[i];
		}

		fill(aa, aa + 10000, 0);
		fill(dp, dp + 10000, 0);

		Int max_i = -999999999;
		dp[0] = max(dp[0], aa[0]);
		max_i = max(max_i, dp[0]);

		for (int i = 1; i < n; ++i){
			dp[i] = max(aa[i], dp[i - 1] + aa[i]);
			max_i = max(max_i, dp[i]);
		}
		cout << max_i << endl;
	}
	return 0;
}

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

int main(void) {
  int n, a[5001];
  long long int sum, mx;
  
  while(cin>>n && n) {
    for(int i = 0; i < n; i++) cin >> a[i];

    mx=-100000*5001;
    for(int i = 0; i < n; i++) {
      sum=0;
      for(int j = i; j < n; j++) {
	sum+=a[j];
	mx=max(mx, sum);
      }
    }
    cout<<mx<<endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int n ;
    cin >> n;
    while(n!=0){
      vector<int>a(n);
      vector<int>S(n+1);
      S.at(0) = 0;
      for(int i = 0;i < n;i++){
        cin >> a.at(i);
      }
      for(int i = 0;i < n;i++){
         S.at(i+1) = S.at(i) + a.at(i);
      }
      int ans = -99999999990990999;
      for(int k = 0; k < n;k++){
      for(int i = 0; i < n-k  ;i++){
        if(S.at(n-k) - S.at(i) > ans){
          ans = S.at(n-k) - S.at(i);
      }
    }
  }
          cout << ans << endl;
          cin >> n;
        }
}