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 <bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n;
        cin>>n;
        if(n==0){
            return 0;
        }
        vector<int> a(n);
        for(int i=0;0<n;i++){
            cin>>a.at(i);
        }
        vector<int> b(n+1);
        b.at(0)=0;
        for(int i=1;i<=n;i++){
            b.at(i)=b.at(i-1)+a.at(i-1);
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            for(int j=0;j<i;j++){
                ans=max(ans,b.at(i)-b.at(j));
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include<iostream>

using namespace std;

int main(){

int n;
int a[10000];
long long int ans = -1000000000;

while(true){

cin >> n;

if(n == 0) break;

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

cin >> a[i];

}

long long int sum;

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

cout << ans << endl;

}

return 0;

}

C++: #include <iostream>
typedef long long ll;
using namespace std;
 
int main(){
    int n,a[5001];
    ll ans;
    a[0]=0;
    while(cin>>n&&n){
        ans = INT_MIN;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            a[i] += a[i-1];
        }
        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                ans = max(ans,a[j]-a[i-1]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

int main()
{
    int n;
    while(cin >> n &&n)
    {
        if(n==0)break;
        long int s[N];
        //memset(s,0,sizeof(int)*N);
        long int t;
        cin >> t;
        /*s[0]=t;max = t;min=t;*/
        s[0] = t;
        long int max = t;
        
        for(int i=1;i<n;i++){
            cin >> t;
            s[i] = s[i-1]+t;
            if(s[i]>max)max=s[i];
            for(int j=0;j<i+1;j++)
            {
                if((s[i]-s[j])>max) max = (s[i]-s[j]);
            }
        }
        cout << max << endl;

    }

    return 0;
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int &x : v) cin >>x;

    for (int i = 1; i < n; i++) {
        v[i] = v[i] + v[i-1];
    }

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

    cout << Max << endl;

    return 0;
}

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=a[0];
		rep(i,0,n){
			int sum=0;
			rep(j,i,n){
				sum+=a[j];
				MAX=max(MAX,sum);
			}
		}
		o(MAX);
	}
}

C++: 
#include<iostream>

using namespace std;

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

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;


int main()
{
	int n;
	cin >> n;
	while(n){
		vector<int>dp;
		dp.pb(0);
		rep(i,n){
			int t;
			cin >> t;
			dp.pb(dp[i]+t);
		}
		int mx=0;
		rp(i,dp){
			REP(j,1,dp.size()){
				mx=max(mx,dp[j]-dp[i]);
			}
		}
		cout << mx << endl;
	}
	return 0;
}

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

int n;
int a[5001];

void add( int i, int x )
{	
	while( i <= n ){
		a[i] += x;
		i += i & (-i);
	}
	
	return;
}

int sum( int i )
{
	if( i == 0 ) return 0;

	int s = 0;
	while( i > 0 ){
		s += a[i];
		i -= i & (-i);
	}
	
	return s;
}

int main()
{
	while( 1 ){
		memset( a, 0, sizeof( a ) );
	
		std::cin >> n;
		if( !n ) break;
		
		for( int i = 1; i <= n; i++ ){
		 	int x;
			std::cin >> x;
			add( i, x );
		}
		
		int ans = 0;
		
		for( int i = 0; i < n; i++ ){
		 	for( int j = i + 1; j <= n; j++ ){
				ans = std::max( ans, sum( j ) - sum( i - 1 ) );
			}
		}
		
		std::cout << ans << std::endl;
	}
	
 	return 0;
}