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 <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <algorithm>
#include <cctype>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);

int n,ans;
vi dp,num;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		ans=-1;
		dp=vi(n);
		num=vi(n);
		for(int i=0;i<n;i++) cin>>num[i];
		dp[0]=num[0];
		for(int i=0;i<n-1;i++) dp[i+1]=max(num[i+1],num[i+1]+dp[i]);
		for(int i=0;i<n;i++) ans=max(ans,dp[i]);
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1LL << 25;
double EPS = 1e-9;

// BEGIN //////////////////////////////////////////////////////////////

int main() {
	while (true) {
		int N = nextInt();
		if (N == 0) break;
		int score = nextInt();
		int score_max = -INF;
		REP(i, N - 1) {
			int d = nextInt();
			score = max(score + d, d);
			score_max = max(score, score_max);
		}
		PRINT(score_max);
	}

	return 0;
}

// END   //////////////////////////////////////////////////////////////

C++: #include <iostream>
#include <limits.h>
using namespace std;
int main(){
	while(1){
		int n ; cin >> n ; if(!n) break;
		int* a=new int[n];
		for(int i=0;i<n;i++) cin >> a[i];
		int MAX=INT_MIN;
		for(int i=0;i<n;i++){
			int temp=a[i];
			for(int j=i+1;j<n;j++){
				temp+=a[j];
				if(temp>MAX) MAX=temp;
			};
		};
		cout << MAX << '\n' ;
		delete[] a;
	};
}

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

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

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

        int ans =-1111111111;
        int sum =0;

        for(int i=n;i>0;i--){
            for(int j=0;j<n;j++){
                int tmp=S[i] - S[j];
                if(ans<tmp){
                    ans = tmp;
                }
            }
        }
        cout<<ans<<endl;
        cin>>n;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define fst	first
#define scn second

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;

int main() {
	while (true) {
		int n;	cin >> n;
		if (n == 0)	break;
		vint a(n, 0);
		rep(i, n)	cin >> a[i];
		vector<ll> sum(n + 1, 0);
		rep(i, n)	sum[i + 1] = sum[i] + a[i];
		ll ret = 0;
		REP(i, n)	rep(j, i)	ret = max(ret, sum[i] - sum[j]);
		cout << ret << endl;
	}
	return 0;
}

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

int main(){
    long long int n, ans, sum;
    long long int a[5001];
    
    while(cin >> n){
        if(n == 0){
            break;
        }
        
        memset(a, 0, sizeof(a));
        
        for(int i = 0;i < n;i++){
            cin >> a[i];
        }
        
        ans = a[0];
            
        for(int i = 0;i < n;i++){
            sum = 0;
                
            for(int j = i;j < n;j++){
                sum += a[j];
                ans = max(sum, ans);
            }
        }
        
        cout << ans << endl;
    }

    return 0;
}

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

int main()
{
	int n,t,mx;
	while(cin >> n, n)
	{
		mx = 0;
		int dt[5000]={0};
		for(int i=0; i<n; i++)
		{
			cin >> t;
			for(int j=0; j<=i; j++)
			{
				dt[j]+=t;
				if(j!=i)mx=max(mx,dt[j]);
			}
		}
		cout << mx << endl;
	}
}

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

int main(){
while(1){
int n;
cin>>n;
if(n==0)break;
vector<int> sum(n+1,0);
for(int i=1;i<=n;i++){
	int a;
	cin>>a;
	sum[i]=sum[i-1]+a;
}
int ans=sum[1];
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;
}

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

		cout << maximum << endl;
		cin >> n;
	}

	return 0;
}

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

int main(){
	vector<int> nums;
	int n;
	while( cin >> n, n ){
		nums.clear();
		nums.resize(n);
		for( int i=0; i<n; i++ )
			cin >> nums[i];
		int max=-50000000;
		for( int i=0; i<n; i++ ){
			int sum=0;
			for( int j=i; j<n; j++ ){
				sum += nums[j];
				if( max < sum )		max = sum;
			}
		}
		cout << max << endl;
	}
}

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