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<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,s,a;
	while(cin>>n,n){
		cin>>a;
		m=s=a;n--;
		while(n--){
			cin>>a;
			if(s<0)s=a;
			else s+=a;
			m=max(s,m);
		}
		cout<<m<<endl;
	}
}

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

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

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

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

using namespace std;

#define int long long
#define pii pair<int,int>

const int MaxN=100*1000+10;
int arr[MaxN];
int ps[MaxN];

int findRightSticky(int s,int e){
	int mx=arr[e];
	int ind=e;
	for (int i=s;i<=e;++i)
		if (mx<ps[e]-ps[i-1]){
			mx=ps[e]-ps[i-1];
			ind=i;
		}
	return ind;
}

int findLeftSticky(int s,int e){
	int mx=arr[s];
	int ind=s;
	for (int i=s;i<=e;++i)
		if (mx<ps[i]-ps[s-1]){
			mx=ps[i]-ps[s-1];
			ind=i;
		}
	return ind;
}

pair<int,int> findMaxSubarray(int s,int e){
	if (s==e)
		return make_pair(s,s);
	int mid=(s+e)/2;
	pii mxsubleft=findMaxSubarray(s,mid);
	pii mxsubright=findMaxSubarray(mid+1,e);
	int mxstickyleft=findRightSticky(s,mid);
	int mxstickyright=findLeftSticky(mid+1,e);
	int totalmx=max(ps[mxstickyright]-ps[mxstickyleft-1],max(ps[mxsubleft.second]-ps[mxsubleft.first-1],ps[mxsubright.second]-ps[mxsubright.first-1]));
	if (totalmx==ps[mxsubleft.second]-ps[mxsubleft.first-1])
		return mxsubleft;
	else if (totalmx==ps[mxsubright.second]-ps[mxsubright.first-1])
		return mxsubright;
	else
		return make_pair(mxstickyleft,mxstickyright);
}

int32_t main(){
	int n;
	cin >> n;
	while(n){
		for (int i=1;i<=n;++i){
			cin >> arr[i];
			ps[i]=ps[i-1]+arr[i];
		}
		pii prd=findMaxSubarray(1,n);
		cout << ps[prd.second]-ps[prd.first-1] << endl;
		cin >> n;
	}
	// cout << prd.first-1 << " " << prd.second-1 << endl;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <numeric>	// require accumulate
#include <climits>

using namespace std;

int main()
{
	string str = "";
	int n;

	while (1){
		getline (cin, str );
		stringstream ssn(str);
		ssn >> n;

		if (n == 0){
			break;
		} // end if

		vector <int> a(n + 1, 0 );
		vector <int> sum (n + 1, 0 );
		int i,j;

		for (i = 1; i <= n; ++i){
			getline (cin, str );
			stringstream ss(str);
			ss >> a[i];
		} // end for

		for (i = 1; i <= n; ++i){
			sum[i] = accumulate (a.begin(), a.begin() + i + 1, 0 );
		} // end for

		int maxn = INT_MIN;
		for (i = 1; i <= n; ++i){
			for (j = i; j <= n; ++j){
				 maxn = max (maxn , sum[j] - sum[i - 1] );
			} // end for
		} // end for

		cout << maxn << endl;			

	} // end while

	return 0;
}

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

template <typename Iterator>
auto findMaximumSum (Iterator begin , Iterator end) -> long long
{
    long long res = * begin;
    auto tmp = res;
    for (auto ite = begin + 1; ite != end; ++ ite)
    {
        tmp += * ite;
        res = std::max (res , tmp);
    }
    return res;
}

auto main () -> int
{
    int n;
    while (std::cin >> n && n)
    {
        std::vector <int> a (n);
        for (auto && elem : a)
        {
            std::cin >> elem;
        }
        long long ans = a [0];
        for (auto ite = a.begin (); ite != a.end (); ++ ite)
        {
            auto tmp = findMaximumSum (ite , a.end ());
            ans = std::max (ans , tmp);
        }
        std::cout << ans << std::endl;
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<int>in(n);
    rep(i,n)cin>>in[i];
    int max=0;
    rep(i,n){
      int sum=0;
      loop(j,i,n){
	sum+=in[j];
	if(max<sum)max=sum;
      }
    }
    cout<<max<<endl;
  }


}

C++: #include<stdio.h>
int main(void)
{
	int a[5000],i,j,sum=0,max[5000]={-10001},c=0,n;
	
	while(1){
		scanf("%d",&n);
		if( n == 0)
			break;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				sum = sum + a[j];
				if(max[c] < sum)
					max[c] = sum;
			}
			sum = 0;
		}
		c++;
	}
	for(i=0;i<c;i++){
		printf("%d\n",max[i]);
	}
	return 0;
}

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

int main(){
	long long int n;
	
	while(cin>>n,n){
		long long int max=0;
		long long int sum[n];
		long long int t;
		int i;
		for(i=0;i<n;i++)cin>>sum[i];
		for(i=t=0;i<n;i++){
			if(t<0)t=sum[i];else t+=sum[i];
			if(max<t)max=t;
		}
		cout<<max<<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; }

ll INF = 1LL << 63;
double EPS = 1e-9;
// BEGIN //////////////////////////////////////////////////////////////


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

	return 0;
}

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