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 <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <cstring>

using namespace std;

int main(){
	int n;
	int max,tmpmax1,tmpmax2;
	while(cin >> n && n != 0){
		max = -100001;
		int *factor = new int[n];
		
		for(int i = 0; i < n; i++){
			cin >> factor[i];
		}

		for(int i = 0; i < n; i++){
			tmpmax1 = 0;
			tmpmax2 = -100001;
			for(int j = i; j < n; j++){
				tmpmax1 += factor[j];
				if(tmpmax2 < tmpmax1){
					tmpmax2 = tmpmax1;
				}
			}
			if(max < tmpmax2){
				max = tmpmax2;
			}
		}
		delete [] factor;
		cout << max << endl;
	}
	
	return 0;
}

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

int main()
{
	int n=1, count = 0;
	int a[10000],ans[10000];
	while (n != 0) {
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = -10000;
		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;
				}
			}
		}
		ans[count] = max;
		count++;
	}
	for (int ci = 0; ci < count-1; ci++) {
		cout << ans[ci] << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int d[5000], a, i, n,ans=-100001,j;
	while (1) {
		cin >> n;
		if (n == 0) {
			break;
		}
		for (i = 0; i < n; i++) {
			cin >> d[i];
		}
		for (i = 1; i < n; i++) {
			d[i] += d[i - 1];
		}
		for (i = 0; i < n; i++) {
			for (j = 0; j < i; j++) {
				ans = max(ans, d[i] - d[j]);
			}
		}
		cout << ans << endl;
		
	}
	return 0;
}

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

using namespace std;

#define N 2<<30;

int main(){

  int n;


  while(cin >> n){
    if(n == 0) break;
    vector<int> V;
    int status;
    int in;
    int sum = 0;
    for(int i = 0; i < n; i++){
      cin >> in;
      if(i == 0){
	if(in < 0){
	  status = -1;
	  V.push_back(in);
	}
	else if(in >= 0)status = 1;

      } else {

	if(in < 0 && status > 0){
	  status = -1;
	  V.push_back(sum);
	  sum = 0;
	  V.push_back(in);
	  continue;
	}else if(in < 0 && status < 0){
	  V.push_back(in);
	  continue;
	}else if(in >= 0 && status < 0){
	  status = 1;
	  V.push_back(sum);
	  sum = 0;
	}
      }
      sum += in;
    }
    if(sum > 0) V.push_back(sum);

    int max = -1*N;
    
    for(int i = 0; i < V.size(); i++){
      sum = 0;
      for(int j = i; j < V.size(); j++){
	sum += V[j];
	if(max < sum) max = sum;
      }
    }
    
    cout << max << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 9999999;
double EPS = 1e-9;
// BEGIN //////////////////////////////////////////////////////////////


int main() {
#define int ll
	while (true) {
		int N = nextInt();
		if (N == 0) break;
		int score = nextInt();
		int score_max = -INF;
		REP(i, N - 1) {
			int d = nextInt();
			score = max(score + d, d);
			score_max = max(score, score_max);
		}
		PRINT(score_max);
	}

	return 0;
}

// END   //////////////////////////////////////////////////////////////

C++: #include <iostream>

using namespace std;

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

void solve(){
  memo[0] = max(0LL, a[0]);
  long long 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 <iostream>

using namespace std;
int a[5000], b[5000], c[5000];

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

    b[0] = a[0];
    for(int i = 1; i < n; i++){
      b[i] = b[i-1] + a[i];
    }

    c[0] = b[0];
    for(int i = 1; i < n; i++){
      c[i] = min(c[i-1], b[i]);
    }

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

C++: #include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int n;
    while(cin>>n){
        if(n==0){
            break;
        }
        int a[n],sum=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }
        cout<<sum<<endl;
    }
    return 0;
}

C++: /*AOJ 0022*/

#include<iostream>
#include<vector>
using namespace std;

int main(){

	int n;

	for(;;){

		cin>>n;

		if(n==0){
			break;
		}

		vector<int> data;
		int max=0;
		int sum=0;

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

			int tmp;
			cin>>tmp;

			data.push_back(tmp);

		}

		for(int i=0;i<n;i++){
			sum = 0;
			if(data.at(i)<0){
				continue;
			}
			for(int j=i;j<n;j++){
				sum+=data.at(j);
				if(sum>=max){
					max = sum;
				}
			}
		}
		data.clear();
		cout<<max<<endl;

	}

	return 0;
}

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

using namespace std;

int main () {
  int n;
  int sum, max_sum;

  while(cin >> n, n){
    vector<int> a;
    for(int i = 0; i < n; i++){
      int temp;
      cin >> temp;
      a.push_back(temp);
    }

    max_sum = a[0];

    for(int begin = 0; begin < n; begin++){
      sum = 0;
      for(int end = begin; end < n; end++){
        sum += a[end];
        if (max_sum < sum){
          max_sum = sum; 
        }
      }
    }

    cout << max_sum << endl;
  }
}

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

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

		long max=S[0];
		for(int i=0;i<n;++i){
			if(S[i]>max) max=S[i];
			for(int j=0;j<i+1;++j){
				if(S[i]-S[j]>max) max=S[i]-S[j];
			}
		}

		cout<<max<<endl;
	}

	return 0;
}

C++: #include <iostream>
int main(){
	int n, v[5000], m;
	while(std::cin >> n, n){
		for(int i=0;i<n;i++)std::cin >> v[i];

		m = v[0];
		for(int i=0;i<n;i++)
			for(int j=i,k=0;j<n;j++,k+=v[j])
				if(k>m)m=k;

		std::cout << m << '\n';
	}	
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>

using namespace std;

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