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

C++: #include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

int n;
vector<int> vec;

int main()
{
	while(cin>>n)
	{
		if(!n) return 0;
		int ans=-INF;
		rep(i,n)
		{
			int a;
			cin>>a;
			vec.pb(a);
			ans=max(ans,a);
		}
		rep(i,n)
		{
			int sum=0;
			for(int j=i;j<n;j++)
			{
				sum+=vec[j];
				ans=max(ans,sum);
			}
		}
		cout<<ans<<endl;
		vec.clear();
	}
	return 0;
}