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<vector>

using namespace std;

int getMaxSum(vector<int> v)
{
	int sum,max;
	sum=v[0];
	max=v[0];
	for(int i=1;i<v.size();i++)
	{
		if(sum<0)
		{
			sum=0;
		}
		sum+=v[i];
		if(sum>max)
		{
			max=sum;
		}
	}
	return max;
}

int main(void)
{
	int n;
	while(cin>>n)
	{
		if(n==0)
		{
			break;
		}
		vector<int> v;
		for(int i=0;i<n;i++)
		{
			int tmp;
			cin>>tmp;
			v.push_back(tmp);
		}
		cout<<getMaxSum(v)<<endl;
	}
}

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

C++: #include<iostream>
using namespace std;
bool same(int a,int b){
  if(a*b>=0) return true;
  return false;
}
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int d;
    int s[n];
    int count = 0,begin = 0;
    int ans;
    for(int i=0;i<n;i++){
      cin >> d;
      if(i==0) s[0] = d;
      else if(same(d,s[count])) s[count] += d;
      else{
	count++;
	s[count] = d;
      }     
    }
    if(count==0){
      cout << s[0] << endl;
      continue;
    } 
    if(s[0]<0) begin = 1;
    for(int i=begin;i<=count;i+=2){
      unsigned long long int h = s[i];
      if(i==begin) ans = s[i];
      else if(ans<h) ans = h;
      for(int j=i+1;j<=count;j++){
	h += s[j];
	if(ans<h) ans = h;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main( void )
{
  int n,prev,d[5001],ret;
  while( 1 ){
    cin >> n;
    if( n==0 ) break;
    cin >> d[0];
    ret = d[0];
    for( int i=1; i<n; i++ ){
      cin >> d[i];
      for( int j=0; j<i; j++ ) d[j] += d[i];
      ret = max( *max_element( d, d+i+1 ), ret );
    }
    cout << ret << endl;
  }
  return 0;
}

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

using namespace std;

int main(void){
	int *a,maxi;
	for(int n;cin >> n,n;){
		maxi = INT_MIN;
		a = new int[n];
		for(int i=0;i<n;i++)
			cin >> a[i];

		for(int i=0;i<n;i++)
			for(int j=i,sum=0;j<n;j++)
				maxi=max(maxi,sum+=a[j]);
		delete [] a;

		cout << maxi << endl;
	}
	return 0;
}

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

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

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

	for (;;){
		cin >> n;
		if (n == 0) break;
		m = 0;
		for (int i = 0; i < n; i++){
			cin >> a[i];
		}
		m = a[0];
		for (int i = 0; i < n; i++){
			sum = 0;
			for (int j = i; j < n; j++){
				sum += a[j];
				m = max(sum, m);
			}
		}

		cout << m << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LLINF = LLONG_MAX;
#define REP(i, n) for (int i = 0; i < n; i++)

int main(){
    ll n, a;
    while(1){
        cin >> n;
        if(n==0)break;
        ll sum = 0, ans = -LLINF, smin = 0;
        REP(i,n){
            cin >> a;
            sum += a;
            ans = max(ans, a);
            if(sum < smin){
                smin = sum;
            }
            else{
                ans = max(ans, sum-smin);
            }
        }
        cout << ans << 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 = 1LL << 25;
double EPS = 1e-9;

// BEGIN //////////////////////////////////////////////////////////////

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

	return 0;
}

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

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

int main(void)
{
	int n;
	long long num, sum = 0, max = -100001;
	
	while(scanf("%d",&n) && n > 0){
		for(int f1 = 0; f1 < n; f1++){
			scanf("%lld",&num);
			sum += num;
			if(max < sum)
			{
				max = sum;
			}
		}
		printf("%lld\n", max);
	}
	return 0;
}

C++: #include<cstdio>
int main(){int n,i,j,s,m,a[5000];while(scanf("%d",&n)&&n){for(i=0;i<n;i++)scanf("%d",&a[i]);m=-500000001;for(i=0;i<n;i++,s=0)for(j=i;j<n;)if((s+=a[j++])>m)m=s;printf("%d\n",m);}}

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

using namespace std;
static const int MAXV = 5000;

int main() {
  while(1) {
    int n;
    double data[MAXV], max=0, sum=0;
    scanf("%d", &n);
    if (n==0) break;
    for(int i=0; i<n; i++) scanf("%lf", &data[i]);
    for (int i=0; i<n; i++) {
      for (int j=i; j<n; j++) {
	sum+=data[j];
	if(max<sum) max=sum;
      }
      sum=0;
    }
    printf("%lf", max);
  }
}

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


int main() {
    int n;
    std::cin >> n;
    while (n != 0) {
        std::vector<int> vec(n+1, 0);
        int x;
        for (int i = 1; i <= n; ++i) {
            std::cin >> x;
            vec[i] = x;
        }
        std::vector<int> sum;
        sum.assign(n+1, 0);
        sum[1] = vec[1];
        for (int i = 1; i < n; i++) {
            sum[i+1] = sum[i] + vec[i+1];
        }
        int ans = -1000000000;
        for (int l = 1; l <= n; ++l) {
            for (int r = l; r <= n; ++r) {
                ans = std::max(ans, sum[r] - sum[l-1]);
            }
        }
        std::cout << ans << std::endl;
        std::cin >> n;
    }
}

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

int main()
{

	int n, num;
	vector< long int > a;

	while( 1 ) {

		int Max = -1000001;

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

		a.push_back( 0 );

		for( int i = 0; i < n; i++ ) {
		
			cin >> num;
			a.push_back( num );
			
		}

		//?????§???
		for( int i = 1; i < n; i++ ) {
		
			a[i - 1] + a[i] > a[i] ? a[i] = a[i - 1] + a[i] : a[i] = a[i];

			if ( a[i] > Max ) {
				Max = a[i];
			}
		
		}

		cout << Max << endl;

		a.clear();
	
	}

	return 0;

}