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>
#include <algorithm>

using namespace std;
typedef long long lint;

int main()
{
	int N;
	
	while (scanf("%d", &N) && N){
		lint maxi = -0x3fffffffffffffll;
		lint dist = maxi;
		for (int i = 0; i < N; i++){
			lint x;
			scanf("%lld", &x);
			dist = max(dist + x, x);
			maxi = max(maxi, dist);
		}
		printf("%lld\n", maxi);
	}
	
	return (0);
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int d[5005];
int main(void){
  while(1){
    int n;
    scanf("%d",&n);
    if(!n) break;
    for(int i=0;i<n;i++){
      scanf("%d",&d[i]);
      if(i) d[i]+=d[i-1];
    }
    int sum=d[0];
    for(int i=0;i<n;i++){
      sum=max(d[i],sum);
      for(int j=0;j<i;j++){
	sum=max(d[i]-d[j],sum);
      }
    }
    printf("%d\n",sum);
  }
}

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

int main(void){

	int a[5001];
	for(int i=0; i<5001; i++) a[i] = 0;

	int n;
	while(cin >> n){
		
		if(n==0) break;
		for(int i=0; i<n; i++){
			cin >> a[i];
		}

		int ans = -999999;
		int sum = 0;

		for(int i=0; i<n; i++){
			for(int j=0; j<(n-i); j++){
				sum = sum + a[i+j];
				if(sum>ans) ans=sum;
			}
			sum = 0;
		}

		cout << ans << endl;

		for(int i=0; i<5001; i++) a[i] = 0;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000],saidai=-100000;
	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+1;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 <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
	int n;
	while(cin >> n && n){
		n++;
		vector<int> t(n), v(n);
		t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}
		cout << *max_element(t.begin(), t.end()) << endl;
	}
	return 0; 
}

/*
7
-5
-1
6
4
9
-6
-7
*/

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

int main()
{
	int n=1, count = 0;
	int a[10000];
	while (cin >> n) {
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = -100000;
		for (int ai = 0; ai < n - 1; ai++) {
			sum = 0;
			for (int bi = ai; bi < n; bi++) {
				sum = sum + a[bi];
				if (sum > max) {
					max = sum;
				}
			}
		}
		if (n == 0)
			break;
		cout << max << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int a[5000],n;
signed main(){
    while(cin>>n,n){
        for(int i=0;i<n;i++)cin>>a[i];
        int ma=LLONG_MIN;
        for(int i=0;i<n;i++){
            int cur=0;
            for(int j=i;j<n;j++){
                cur+=a[j];
                ma=max(ma,cur);
            }
        }
        cout<<ma<<endl;
    }

    return 0;
}

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

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;


int main(void){

int nm=9;
int sum,j;
int su[5001]={0};

	while(1){
		cin >> nm;
		if(nm == 0) break;
		int mx = -999999999;
		rep(i,nm) cin >> su[i];
		rep(i,nm){
			sum=0;
			rep2(j,i,nm){
		 		sum += su[j];
				mx = max(mx,sum);
			}
		}
		cout << mx << endl;
	}
	return 0;
}

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

int main(){
  int n;
  int list[5000];

  while(cin>>n){
    if(n==0){
      break;
    }
    int temp=0;
    int max=0;
    for(int i=0; i<n; i++){
      cin >> list[i];
    }

    for(int i=0; i<n; i++){
      temp += list[i];
      if( temp<=0 ){
        temp=0;
      }
      if(max<temp){
        max=temp;
      }
    }

    cout << max << endl;
  }

  return 0;
}

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