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>
int main()
{
	while (!std::cin.eof())
	{
		int n;
		std::cin >> n;
		if (n == 0)
		{
			break;
		}
		std::vector<int>a(n);
		for (auto&i : a)
		{
			std::cin >> i;
		}
		int max = -100001;
		for (int i = 0; i < n; i++)
		{
			int max_temp = 0;
			for (int j = 0; j < n - i; j++)
			{
				max_temp += a[i + j];
				if (max < max_temp)
				{
					max = max_temp;
				}
			}
		}
		std::cout << max << std::endl;
	}
	return 0;
}

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


int main(){
  int n; 
  while(true){
    cin >> n;
    if(n == 0) break;

    vector<int64_t> a(5010), sum(5010, 0); 
    for(int i=1; i<=n; i++){
      cin >> a[i];
      sum[i] = sum[i-1] + a[i];
    }

    int64_t ans = -99999999;
    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<iostream>
#include<cstdio>
using namespace std;
int main()
{
  int n,sum = 0,ans,sumkeep;
  
  while(cin >> n){
    if(n == 0)break;
    
    ans = 0;
    sumkeep = 0;

    int a[n];
    
    for(int i = 0;i < n;i++){
      cin >> a[i];
    }
    
    for(int i = 0;i < n;i++){
      sumkeep = 0;
      for(int j = i;j < n;j++){
	sumkeep += a[j];
	if(i == 0 && j == 0){
	  ans = sumkeep;
	}
	else if(ans < sumkeep){
	  ans = sumkeep;
	}
      }
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main (){
while (1){
long n,dset[5000],temp=0,MINEdset[5000],max,h[5000],b=0;
cin>>n;
if (n==0)break;
for (int i=0;i<n;i++){
        cin>>dset[i];
}
max=dset[0];
for (int i=0;i<n;i++){
        for (int j=i;j<n;j++){
                temp=temp+dset[j];
                MINEdset[j]=temp;
        }
        for (int j=i;j<n;j++){
                if (max<MINEdset[j]){
                        max=MINEdset[j];
                }
        }
        h[b]=max;
        max=dset[0];
        b++;
        temp=0;
}
max=dset[0];
for (int i=0;i<=b;i++){
        if (max<h[i]){
                max=h[i];
        }
}
cout<<max<<endl;
}
return 0;
}

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

using namespace std;
int main(void)
{
    int n, a[10000];
    while (1) {
        cin >> n;
        if (n == 0)
            break;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        int goukei = 0, led = -10000000;
        for (int i = 1; i <= n; i++)
        {
            goukei = 0;
            for (int j = i; j <= n; j++)
            {
                goukei = goukei + a[j];
                led = max(goukei, led);
            }
        }
        cout << led << endl;
    }
    return 0;
}

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

	int n, max=0;
	int *a;
	int 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>
#include <vector>
using namespace std;

int main(){
    int n;
    while(cin >> n && n){
        vector<int> a(n,0);
        for(int i=0; i<n; ++i){
            cin >> a[i];
        }
        vector<int> dp(n,0);
        dp[0] = a[0];
        int max = 0;
        for(int i=1; i<n; ++i){
            if(dp[i-1]>0){
                dp[i] = dp[i-1] + a[i];
            } else {
                dp[i] = a[i];
            }
            if(max<dp[i]){
                max = dp[i];
            }
        }
        cout << max << endl;
    }
}

C++: // 2014/08/30 Tazoe

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

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

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

		int DP[5000];
		DP[0] = a[0];
		int s_max = DP[0];

		for(int i=1; i<n; i++){
			DP[i] = max(DP[i-1]+a[i], a[i]);

			s_max = max(s_max, DP[i]);
		}

		cout << s_max << endl;
	}

	return 0;
}

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

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

typedef long long ll;

int main() {
  
  int N;
  while(cin >> N && N) {
    vector<int> in(N);
    rep(i, N) cin >> in[i];
    vector<int> v(N);
    int mx = -1<<29;
    rep(i, N) {
      if(i-1 >= 0 && v[i-1] >= 0) {
	v[i] = v[i-1] + in[i];
      }
      else {
	v[i] = in[i];
      }
      if(mx < v[i]) { mx = v[i]; }
    }
    cout << mx << endl;
  }
  
  return 0;
}

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

using namespace std;

int calc (vector<int> a, int i, int n) {
    int s = 0, j;
    for (j = 0; j < n; j++) {
        s += a[i + j];
    }
    return s;
}

inline int max (int a, int b) {
    return a > b ? a : b;
}

int main (void) {
    int n, i, j;
    while (1) {
        cin >> n;
        if (n == 0) break;
        vector<int> a(n);
        for (i = 0; i < n; i++) {
            cin >> a[i];
        }
        int sum = 0, s;
        for (i = 1; i <= n; i++) {
            for (j = 0; j + i <= n; j++) {
                s = calc(a, j, i);
                sum = max(sum, s);
            }
        }
        cout << sum << endl;
    }
    return 0;
}

C++: #ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int main()
{
	int N;
	while (cin >> N, N)
	{
		vector<long long int>data;
		data.resize(N + 1);
		data[0] = 0;
		for (size_t i = 1; i <= N; i++)
		{
			cin >> data[i];
			data[i] += data[i - 1];
		}
		long long int ans = INT_MIN;
		for (size_t i = 0; i < N + 1; i++)
		{
			for (size_t j = i; j < N + 1; j++)
			{
				ans = max(ans, data[j] - data[i]);
			}
		}
		cout << ans << endl;
	}
}