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++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>

typedef long long Int;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
using namespace std;

int main(){
	int n;
	while (cin >> n, n){
		Int aa[10000];
		Int dp[10000];


		REP(i, n){
			cin >> aa[i];
		}

		Int max_i = -999999999;
		dp[0] = max(dp[0], aa[0]);
		max_i = max(max_i, dp[0]);

		for (int i = 1; i < n; ++i){
			dp[i] = max(aa[i], dp[i - 1] + aa[i]);
			max_i = max(max_i, dp[i]);
		}
		cout << max_i << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main() {
        int n, a;

        while (true) {
                scanf("%d", &n);
                if (!n) {
                        break;
                }

                int sum = 0, max = 0;
                for (int i = 0; i < n; i++) {
                        scanf("%d", &a);
                        sum += a;
                        if (sum < 0) {
                                sum = 0;
                        }
                        if (sum > max) {
                                max = sum;
                        }
                }
                printf("%d\n", max);
        }

        return 0;
}

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

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

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

int main(){
    int n;


    while(cin >> n, n != 0){
        vector<int> a(n);
        for(int i=1; i<=n; i++){
            cin >> a[i];
        }

        int minimum = 0;
        int x = 0;
        int maximum = -(1<<29);
        for(int i=0; i<=a.size(); i++){
            x += a[i];
            maximum = max(maximum, x-minimum);
            minimum = min(minimum, x);
        }

        cout << maximum << endl;

    }

    return 0;
}

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

  int dataSets;

  while(true){
    vector<int> a;
    cin >> dataSets;
    if(dataSets==0){break;}
    for(int i=0;i<dataSets;i++){
      int tmpa;
      cin >> tmpa;
      a.push_back(tmpa);
      // cout << "a[" << i << "]: " << a[i] << endl;
    }

    int max=0;
    
    for(int i=0;i<dataSets;i++){
      // i+1?????£?¶?
      for(int j=0;j<dataSets-i;j++){
	int tmp=0;
	for(int k=0;k<i+1;k++){
	  tmp += a[j+k];
	  // cout << "(i,j,k): " << i << "," << j << "," << k << "  " << "a[" << j+k << "]   max:" << max << endl;
	}
	if(tmp>max){max=tmp;}
      }
    }
    
    cout << max << endl;
    
  }

  return 0;

}

C++: #include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
long long p[5001]={0};
int main(){
while(1){
memset(p,0,sizeof(p));
long long n,i,j,t,a;
cin>>n;
if(n==0)break;
for(i=1;i<=n;i++){
cin>>a;
p[i]=p[i-1]+a;
}
t=0;
for(i=1;i<=n;i++){
	for(j=0;j<i;j++)t=max(t,p[i]-p[j]);
}
cout<<t<<endl;
}
return 0;
}

C++: #include <iostream>
main(){for(int n,i,m,a[5000],j,s;std::cin>>n,n;std::cout<<m<<"\n"){for(i=0;i<n;)std::cin>>a[i++];for(i=0,m=-1e9;i<n;)for(j=i++,s=0;j<n;m=s>m?s:m,j++)s+=a[j++];}}

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

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << "\n";
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;

//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos( -1.0 );

//global-----------------------------------------------------------------------------------------------------------------------
int n;
VI ar;
LL ans = 0;

//function---------------------------------------------------------------------------------------------------------------------
void solve( int now_check, LL sum ) {
	if ( ans < sum ) {
		ans = sum;
	}
	if ( now_check == n ) {
		return;
	}
	if ( sum + ar[ now_check ] <= 0 ) {
		solve( now_check + 1, 0 );
	}
	else {
		solve( now_check + 1, sum + ar[ now_check ] );
		if ( ar[ now_check ] < 0 ) {
			solve( now_check + 1, 0 );
		}
	}
}

int main() {
	while ( scanf( "%d", &n ) ) {
		if ( !n ) {
			return 0;
		}
		ans = 0;
		ar.resize( n );
		rep( i, n ) {
			scanf( "%d", &ar[ i ] );
		}
		solve( 0, 0 );
		printf( "%lld\n", ans );
	}
	return 0;
}

C++: #include <cstdio>
#include <bitset>
#include <cmath>
#include <complex>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#define EPS 1e-6

using namespace std;
typedef complex<double> coor;

double cross(coor a, coor b)
{
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(coor a, coor b)
{
  return a.real() * b.real() + a.imag() * b.imag();
}

int main()
{
  int N;
  while (scanf(" %d ", &N) == 1) {
    if (N == 0) {break;}
    vector<int> series(N);
    
    for (int i = 0; i < N; i++) {
      int n;
      scanf(" %d ", &n);
      series[i] = n;
    }
    
    int mx = 0;
    for (int i = 0; i < N; i++) {
      int sum = 0;
      for (int j = i; j < N; j++) {
	sum += series[j];

	mx = max(mx, sum);
      }
    }
    printf("%d\n", mx);
  }
  return 0;
}