Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

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;
	}
}

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

int main(){
  int n, num, a, maxx;

  while(cin >> n){
    if(n==0) return 0;

    num = maxx = 0;

    for(int i=0;i<n;i++){
      cin >> a;
      num += a;
      if(num<0) num = 0;
      maxx = max(maxx,num);
    }

    cout << num << endl;
  }

  return 0;
}

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

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

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

int main(){
	int n;
	cin >> n;
	while(n != 0){	

		int a[n];
		int sum[n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				sum[i][j] = 0;
			}
		}

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

		for(int i = 0; i < n - 1 ; i++){
			sum[i][0] = a[i];
			for(int j = 0; j < n - i; j++){
				sum[i][j+1] = sum[i][j] + a[i+j+1];
				maximum = max(maximum, sum[i][j]);
			}
		}

		maximum = max(maximum, a[n-1]);
		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#define ll long long int
using namespace std;
typedef pair<int, int> P;

int main()
{
  ll n,a;
  ll i,j;
  ll b[5005]={};

  while(1){
priority_queue<int> pq;
    cin>>n;
    if(n==0)break;
    for(i=1;i<=n;i++){
      cin>>a;
      b[i]=b[i-1]+a;
      for(j=i;j>=0;j--)
	pq.push(b[i]-b[j]);
    }
    cout<<pq.top()<<endl;
  }
}

C++: #include <iostream>

using namespace std;

int A[50000]={0};

int main(){
  int n;

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

    long maxsum = -1000000;
    int prefix_sum[50001]={0};
    prefix_sum[0] = 0;
    for(int i=0;i<n;++i){
      prefix_sum[i+1]=prefix_sum[i]+A[i];
    }
    for(int i=0;i<n+1;++i){
      for(int j=i;j<n+1;++j){
        if(prefix_sum[j]-prefix_sum[i]>maxsum){
          maxsum = prefix_sum[j]-prefix_sum[i];
        }
      }
    }
    cout << maxsum << endl;
  }

  return 0;
}

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

using namespace std;

#define N 2 << 20;

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;
	else if(in > 0)status = 1;
	else{
	  V.push_back(0);
	  status = 0;
	}


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

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

    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 <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int main()
{
	int n;
	int a[5005];
	while (cin >> n, n)
	{
		memset(a, 5005, 0);
		REP(i, n) cin >> a[i];
		int s[5005];
		s[0] = 0;
		FOR(i, 1, n+1) s[i] = s[i - 1] + a[i-1];
		int ans = -INF;
		REP(i, n)
		{
			for (int j = i + 1; j < n+1; j++)
			{
				ans = max(ans, (s[j] - s[i]));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#define INF 20000000
int array[5001];
int n,i,sum,k=0;
void tansaku(int a)
{
    k += array[a];
    if(k > sum)
    {
        sum = k;
    }
    if(a == n-1)return;
    tansaku(a+1);
}
int main(void)
{
    while(1)
    {
        for(i=0;i<5001;i++)
        {
            array[i] = 0;
        }
        scanf("%d",&n);
        if(n==0)break;
        for(i=0;i<n;i++)
        {
            scanf("%d",&array[i]);
        }
        sum = -INF;
        for(i=0;i<n;i++)
        {
            tansaku(i);
            k = 0;
        }
        printf("%d\n",sum);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int n;
int a[5001];
int b[5001];
int s;
int main()
{
	while(cin >> n && n>0)
	{
		b[0]=0;
		cin >> a[1];
		b[1]=a[1];
		s=b[1];
		for(int i=2; i<=n; i++)
		{
			cin >> a[i];
			b[i]=b[i-1]+a[i];
			for(int j=0; j<i; j++)
			{
				s=max(s, b[i]-b[j]);
			}	
		}
		cout << s << endl;
	}
	return 0;
}