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>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.MSS", "r", stdin );
	int n;
	while (scanf ("%d", &n ), n ){
		vector<int> a (n+1, 0 );
		vector<int> sum (n+1, 0 );
		for (int i = 1; i <= n; i++ ){
			scanf ("%d", &a[i] );
		} // end rep
		for (int i = 1; i <= n; i++ ){
			sum[i] = sum[i-1] + a[i];
		} // end for
		int res = 0;
		for (int i = 1; i <= n; i++ ){
			int curr = 0;
			for (int j = i; j <= n; j++ ){
				curr = sum[j] - sum[i-1];
				res = max (res, curr );
			} // end for
		} // end for
		printf ("%d\n", res );
	} // end loop
	
	return 0;
}

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

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

  while(1){
    cin >> n;
    if(n==0) break;
    sum=0;
    ans=-1000000;
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    for(int i=0;i<n;i++){
      sum=0;
      for(int j=0;i+j<n;j++){
	sum+=a[i+j];
	if(ans<sum){
	  ans=sum;
	}
      }
    }
      cout << ans << endl;
  }

}

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

using namespace std;

int main() {
  int N;
  while (cin >> N) {
    if (N == 0) break;
    int num[5000];
    int m = 0;
    for (int i = 0; i < N; i++) {
      cin >> num[i];
    }
    for (int i = 0; i < N; i++) {
      int sum = 0;
      for (int j = i; j < N; j++) {
        sum += num[j];
        m = max(m, sum);
      }
    }
    cout << m << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
  int n;
  vector<int> datas;
  vector<int> sums;

  while (cin >> n, n != 0) {
    int input;
    for (int n_i = 0; n_i < n; n_i++) {
      cin >> input;
      datas.push_back(input);
    }
    for (int data_i = 0; data_i < n-1; data_i++) {
      sums.push_back(datas[data_i]+datas[data_i+1]);
    }

    int max = *sums.begin();
    for (auto sum_i = sums.begin(); sum_i != sums.end(); sum_i++)
      if (max < *sum_i)
        max = *sum_i;
    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;
	}
	return 0;
}

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

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
using namespace std;

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		vector<int> a(n);
		rep(i,0,n) cin>>a[i];
		int MAX=0;
		rep(i,0,n-1){
			int sum=a[i];
			rep(j,i+1,n){
				sum+=a[j];
				MAX=max(MAX,sum);
			}
		}
		o(MAX);
	}
}

C++: #include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int n, a[5010], sum[5010], res;
  while (true) {
    cin >> n;
    if (n == 0) break;
    rep (i, n) cin >> a[i];
    sum[0] = 0;
    rep (i, n) sum[i + 1] = a[i] + sum[i];
    res = -1000000000;
    rep (i, n) rep (j, i) {
      res = max(res, sum[i + 1] - sum[j]);
    }
    cout << res << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int n, i, k;
    int data[5000];
    while (cin >> n) {
        if (n == 0) {
            break;
        }
        int pdata [5001] = {0};
        int result = 0;
        for (i = 0; i < n; i++) {
            cin >> data[i];
        }
        for (i = 0; i < n; i++) {
            pdata[i + 1] = pdata[i] + data[i];
        }
        for (i = 0; i < n + 1; i++) {
            for (k = 0;  k < n + 1; k++) {
                if (result < pdata[i + k] - pdata[i]) {
                    result = pdata[i + k] - pdata[i];
                }
            }
        }
        cout << result << endl;
    }
    return 0;
}

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

int main(){
	int n;
	while ( cin >> n ){
		if ( !n ) break;
		int* a = new int[ n ];
		for ( int i = 0; i < n; ++i ){
			cin >> a[ i ];
		}
		int sum, max = a[ 0 ];
		for ( int i = 0; i < n; ++i ){
			sum = 0;
			for ( int j = i; j < n; ++j ){
			sum += a[ j ];
			if ( sum > max ) max = sum;
			}
		}
		cout << max << endl;
		delete[] a;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 

int main(void){  
  int n;
  while(cin>>n,n){
    int sum = 0, maxs = 0, a[10000];
    REP(i,n)
      cin >> a[i];
    FOR(k,1,n){
    FOR(i,0,k){
      sum += a[i];
      maxs = max(sum, maxs);
    }
    FOR(i,0,k){
      sum -= a[i];
      maxs = max(sum, maxs);
    }
    }
    cout << maxs << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int a;
		int b = 0;
		int max = -1000000;
		for(int i=0;i<n;i++){
			cin >> a;
			b += a;
			if(max<b) max = b;
		}
		cout << max << endl;
	}
}