Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sum := make([]int, 5001)
	for {
		n := nextInt()
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			a := nextInt()
			sum[i+1] = sum[i]+a
		}
		ret := sum[1]
		for i := 0; i <= n; i++ {
			for j := i + 1; j <= n; j++ {
				ret = max(ret, sum[j]-sum[i])
			}
		}
		fmt.Println(ret)
	}
}

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

using namespace std;

template<typename T>
T m(T a, T b) { return a > b ? a : b; }

int main(void) {
    int N;

    while(true) {
        cin >> N;
        if(N == 0) break;
        vector<int> v(N);

        for(int i = 0; i < N; i++) cin >> v[i];

        long long mx = 0L;

        for(int i = 0; i < N; i++) {
            long long tmp = 0L;
            for(int j = i; j < N; j++) {
                tmp += v[j];
                mx = m(mx, tmp);
            }
        }
        cout << mx << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
int n,Sum,Ans ;

while(1){

Ans=0 ;

cin >> n ;

if(n==0){
break ;
}

vector<int> vec(n),vec2(n+1,0) ;

for(int i=0;i<n;i++){
cin >> vec.at(i) ;
}

for(int j=0;j<n;j++){
vec2.at(j+1)=vec.at(j)+vec2.at(j) ;
}

for(int k=0;k<n+1;k++){
    for(int l=k+1;l<n+1;l++){
    Sum=vec2.at(l)-vec2.at(k);
    Ans=max(Sum,Ans) ;
    }
}

cout << Ans << endl ;

}

}

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

using namespace std;

int main(){

  int n;


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


      } else {
	if(in == 0) {
	  V.push_back(0);
	  sum = 0;
	}

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

    V.push_back(sum);

    int max = -700000000;
    
    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++: #define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
using namespace std;

int main(){
	int N;
	while(cin >> N && N > 0){
		int a[N];
		REP(i,N){
			cin >> a[i];
		}

		int maximum = a[0];
        REP(i,N-1){
            int sum = 0;
            int maximum_i = 0;
            for(int j = i; j < N; j++){
					sum += a[j];
                    maximum_i = max(sum,maximum_i);
            }
            maximum = max(maximum,maximum_i);
		}
		cout << maximum << endl;
	}
}

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

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

    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;
      }
    }
    cout << Max << endl;
  }
  return 0;
}

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 - 1; i++){
			tmpmax1 = 0;
			tmpmax2 = -100001;
			for(int j = i; j < n; j++){
				tmpmax1 += factor[j];
				if(tmpmax2 < tmpmax1){
					tmpmax2 = tmpmax1;
				}
			}
			if(tmpmax2 < 0){
				for(int i = 0; i < n; i++){
					if(tmpmax2 == factor[i]){
						if(i != n - 1 && factor[i + 1] < 0){
							tmpmax2 += factor[i + 1];
							break;
						}
					}
				}
			}
			if(max < tmpmax2){
				max = tmpmax2;
			}
		}
		delete [] factor;
		cout << max << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<long int> a,b;
    for(int i=0,j; i<n; i++){
      cin >>j;
      a.push_back(j);
      if(i != 0) a[i]+=a[i-1];
    }
    b.push_back(0);
    for(int i=1; i<n; i++) b.push_back(min(b[i-1],a[i]));
    long int ans = a[0];
    for(int i=1; i<n; i++) ans = max(ans,a[i]-b[i]);
    cout <<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){

	long n, max=0;
	long *a;
	long sum;

	do{
		max = -1000000;
		//cout << endl;
		cin >> n;

		if (n == 0) break;

		a = new long[n + 1];

		sum = 0;

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

			sum = 0;

			cin >> a[i];

			for (int j = i; j >= 0; j--){

				sum += a[j];
				if (max < sum) max = sum;
			}
		}

		cout << max << endl;
	} while (1);
}

C++: #include<iostream>
int n[5000];
int main(){
	while(1){
		int a;
		std::cin >> a;
		if(a==0)break;
		int dp[5000];
		for(int i = 0; i < a; ++i){
			std::cin >> n[i];
		}
		int max = 0;
		dp[0]=n[0];
		for(int i = 1; i < a; ++i){
			if(dp[i-1]>0)dp[i] = dp[i-1] + n[i];
			else dp[i]=n[i];
			if(max < dp[i])max=dp[i];
		}
		std::cout<<max<<std::endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#define ll long long
#define INF (1<<30)
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		vector<ll> a(n);
		vector<ll> Sum(n+1);
		for (int i = 0; i < n; i++) cin >> a[i];
		Sum[0] = 0;
		for (int i = 1; i <= n;i++) Sum[i] = a[i-1] + Sum[i - 1];

		ll ans = -INF;

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

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

int n ;
int ans ;
int numlist[5010] ;

void proc ( ) ;

int main ( )
{
	while ( scanf ( "%d" , &n ) == 1 && n ) {
		for ( int i = 0 ; i < n ; i++ ) {
			scanf ( "%d" , &numlist[i] ) ;
		}
		ans = -1 ;
		proc ( ) ;
		printf ( "%d\n" , ans ) ;
	}
	return 0 ;
}

void proc ( )
{
	for ( int i = 0 ; i < n - 1 ; i++ ) {
		for ( int j = i + 1 ; j < n ; j++ ) {
			int total = 0 ;
			for ( int k = i ; k <= j ; k++ ) {
				total += numlist[k] ;
			}
			ans = ( total > ans ) ? total : ans ;
		}
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

bool solve() {
  int n;
  cin >> n;
  if (n == 0) return false;
  vector<int> a(n);
  for (int& i : a) cin >> i;
  int sum = 0, res = a[0];
  for (int i = 0; i < n; ++i) {
    res = max(res, sum + a[i]);
    if (sum + a[i] < 0) sum = 0;
    else sum += a[i];
  }
  cout << res << endl;
  return true;
}

int main() {
  while (solve());
}

C++: #define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
using namespace std;

int main(){
	int N;
	while(cin >> N && N > 0){
		cout << endl;
		int a[N];
		REP(i,N){
			cin >> a[i];
		}

		int maximum = a[0];
        REP(i,N){
            int sum = 0;
            int maximum_i = 0;
            for(int j = i; j < N; j++){
					sum += a[j];
                    maximum_i = max(sum,maximum_i);
            }
            maximum = max(maximum,maximum_i);
		}
		cout << maximum;
	}
}

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

int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0) break;
    int i,cr,max;
    cr=0;
    max=-100000;
    while(n--){
      cin>>i;
      cr +=i;
      if(cr<0) cr=0;
      if(cr>max) max=cr;
    }
    cout<<max<<endl;
  }
  return 0;
}