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 <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int a[5010];
int dp[5010];
int main(){
	while(cin>>n,n){
		for(int i =0;i < n;i++){
			cin>>a[i];
			dp[i+1]=a[i];
		}
		dp[0] = 0;
		int ans = 0;
		for(int i =1;i <= n;i++){
			dp[i] =max(dp[i-1]+a[i-1],dp[i]);
			ans =max(ans,dp[i]);
		}
		cout <<ans<<endl;
	}
	return 0;
}

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

vector<int> num;

int main(void){
  while(true){
    int maximum = 0, n;
    cin >> n;
    if(!n)  break;
    num.clear();
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      num.push_back(tmp);
    }
    for(int i = 0; i < num.size(); i++){
      int sum = num[i];
      for(int j = i + 1; j < num.size(); j++){
        sum += num[j];
        if(sum > maximum) maximum = sum;
      }
      if(sum > maximum) maximum = sum;
    }
    cout << maximum << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000],saidai=0;
	while(cin>>n&&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<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-1;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>  
#include<cstdio>  
#include<cstring>  
#include <deque> 
using namespace std;  

bool state = false ;

int main()
{
	int n ;
	while(1)
	{
		cin >> n ;
		if( ! n ) return 0 ;
		
		int p[5005];
		
		for(int i = 0 ; i < n ; i ++)
		{
			cin >> p[i] ;
		}
		
		long long max , contain ;
		contain = 0 ;
		max = 0x3f3f3f3f ;
		max *= -1 ;
		
		for(int i = 0 ; i < n ; i ++)
		{
			if(contain < 0) contain = 0 ;
			 
			contain += p[i] ;
			
			if(contain > max) max = contain ;
		}
		
	//	if(state) cout << endl ;
		
	//	state = true ;
	
		cout << max << endl ;
		
	} 
	return 0 ;
 }

C++: #include <iostream>

using namespace std;

int n, a[5010], memo[5010];

void solve(){
  memo[0] = max(0, a[0]);
  int ans = 0;
  for(int i = 1 ; i < n ; i++){
    memo[i] = max(memo[i], memo[i-1]+a[i]);
    ans = max(memo[i], ans);
  }
  cout << ans << endl;
}
int main(){

  while(cin >> n, n){
    fill(memo, memo+n, 0);
    for(int i = 0 ; i < n ; i++){
      cin >> a[i];
    }
    solve();
  }
  return 0;
}

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

int main() {
	while(true) {
		int n; scanf("%d", &n);
		if(n==0) break;
		int submax; scanf("%d", &submax);
		int maxval = submax;
		for(int i = 1; i < n; i++) {
			int a; scanf("%d", &a);
			submax = max(a, submax+a);
			maxval = max(maxval, submax);
		}
		printf("%d\n", maxval);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,a[5000];
	while(1){
		int maxa=-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];
				maxa=max(maxa,sum);
			}
		}
		printf("%d\n",maxa);
	}
	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 = 0;
    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>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int dp[n][n];
    vector<int>a(n);
    int ans=-2000000000;
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++){
      cin>>a[i];
      for(int j=0;j<=i;j++){
	if(j!=i){
	  dp[j][i]+=a[i]+dp[j][i-1];
	}else{
	  dp[j][i]=a[i];
	}
	ans=max(ans,dp[j][i]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int sum[5001] = {};
	while (cin >> n, n)
	{
		//累積和の配列を作る
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			sum[i + 1] = sum[i] + a;
		}

		//さっき作った配列の中から最大値を選ぶ
		int ret = sum[1];
		for (int i = 0; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				ret = max(ret, sum[j] - sum[i]);
			}
		}
		cout << ret << endl;
	}
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;

int main()
{
	int n;

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

		int sum = 0, input, maxer = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> input;
			sum += input;

			if (sum < 0)
				sum = 0;
			maxer = max(sum, maxer);
		}

		cout  <<  maxer << endl;
	}


	return 0;
}

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

int main(){
	int i, j, k, n, sum, result, head, head_before;
	int a[5000];
	while(cin >> n){
		if(n == 0){
			break;
		}
		result = 0;
		head = 0;
		head_before = 0;
		for (i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (i = 0; i < n; i++) {
			if(head > head_before){
				continue;
			}
			for (j = 1; j <= n-i; j++) {
				sum = 0;
				for (k = 0; k < j; k++) {
					sum += a[i+k];
				}
				if(result < sum){
					result = sum;
				}
			}
			head_before = head;
			head += a[i];
		}
		cout << result << endl;
	}
	return 0;
}