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<algorithm>
using namespace std;

int main(){
	
	int n;
	int in[5000],ans;
	
	while(cin>>n,n !=0){
		for(int i=0;i<n;i++){
			cin>>in[i];
		}
		ans=0;
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=i;j<n;j++){
				sum=sum+in[j];
				ans=max(sum,ans);
			}
		}
		
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

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

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

using namespace std;

int debug = 0;

int main(void){
	int n, m, i, j, k;
	int tmp, max;
	vector<int> intv;

	while(cin >> n){
		if(n == 0){
			break;
		}else{
			//ÇÝÝ
			for(i=0;i<n;i++){
				cin >> m;
				intv.push_back(m);
				//if(debug) cout << "int[" << i << "] =" << intv[i] << endl; 
			}

			//vfð¸ç·
			tmp=0;
			for(i=1;i<intv.size();i++){
				if(intv[tmp] > 0){
					if(intv[i] > 0){ //¯Èç
						intv[tmp] += intv[i];
						intv[i] = 0;
					}else{ //ÙÈç
						tmp = i;
					}
				}else if(intv[tmp] < 0){
					if(intv[i] < 0){
						intv[tmp] += intv[i];
						intv[i] = 0;
					}else{
						tmp = i;
					}
				}
			}
			/*
			if(debug){
				for(i=0;i<intv.size();i++){
					cout << intv[i] <<endl;
				}
				cout << "----------------------" << endl;
			}
			*/
			intv.erase( remove(intv.begin(), intv.end(), 0), intv.end());
			/*
			if(debug){
				for(i=0;i<intv.size();i++){
					cout << intv[i] <<endl;
				}
			}
			*/

			max = 0;
			int vsize = intv.size();
			for(i=1;i<=vsize;i+=2){//i:Â
				//if(debug) cout << "number =" << i << endl;
				for(j=0;j<=vsize-1-i+1;j++){ //j:JnÊu
					tmp = 0;
					for(k=0;k<i;k++){
						tmp += intv[j+k];
					}
					//if(debug) cout << "tmp ==" << tmp << endl;
					if(max <= tmp){
						max = tmp;
					}
				}
			}
			cout << max << endl;
			intv.clear();
		}
	}
	return 0;
}

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

using namespace std;

int main() {
  int n;
  vector<int> datas;
  vector<int> sums;

  while (cin >> n, n != 0) {
    int input;
    for (int n_i = 0; n_i < n; n_i++) {
      cin >> input;
      datas.push_back(input);
    }
    for (int data_i = 0; data_i < n-1; data_i++) {
      sums.push_back(datas[data_i]+datas[data_i+1]);
    }

    int max = *sums.begin();
    for (auto sum_i = sums.begin(); sum_i != sums.end(); sum_i++)
      if (max < *sum_i)
        max = *sum_i;
    cout << max << endl;
  }

  return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int n;

	while(cin >> n, n) {
		vi num(n);

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

		int ans = INT_MIN;
		FOR(i, 0, n-1) {
			int sum = 0;
			FOR(j, i, n-1) {
				sum += num[j];
				ans = max(sum, ans);
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

int main(){
	int n;
	while(cin >> n, n){
		n++;
		vector<int> t(n), v(n);
		t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}
		cout << *max_element(t.begin()+1, t.end()) << endl;
	}
	return 0; 
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int n,sumax,temp;
	int num[5001];
	
	while(scanf("%d",&n)){
		if(n==0)
		break;
		for(int i=0;i<n;i++){
			scanf("%d",&num[i]);
		}
		sumax = -100000;
		for(int i=0;i<n;i++){
			temp = 0;
			for(int j=i;j<n;j++){
				temp+=num[j];
				if(temp>sumax)
				sumax=temp;
			}
		}
		printf("%d\n",sumax);
	}
}

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

int main(){
	int n;
	while(cin >> n, n){
		n++;
		vector<int> t(n), v(n);
		t[0] = v[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}
		cout << *max_element(t.begin(), t.end()) << endl;
	}
	return 0; 
}

/*
7
-5
-1
6
4
9
-6
-7
*/

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 
 using namespace std;
 
 int arr[5000+5];
  
 int main()
 {
   int n;
   while(cin>>n&&(n!=0))
   {
     int sum=0;
     int max=0;
     for(int i=0;i<n;i++)
     {
       cin>>arr[i];
       if((sum+arr[i])>0)
       { 
         sum=sum+arr[i];
         if(sum>max) max=sum;
       }        
       else sum=0;
     }            
     cout<<max<<endl;         
   }
   //while(1);      
   return 0;    
 }

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


int n;
ll a[6000];

ll sum(int i,int j){
	ll s=0;
	rep(k,j){
		s+=a[i+k];
	}
	return s;
}

int main(){
	while(cin>>n,n!=0){
		int c=0;
		ll MAX=-1000000000000000000;
		rep(i,n) a[i]=0;
		
		int cou=0;
		rep(i,n){
			cou++;
			cin>>a[0];
			if(a[0]!=0){
				break;
			}
			
		}
		n-=cou;
		rep(i,n){
			int t;
			cin>>t;
			if(a[c]>0&&t>0){
				a[c]+=t;
			}
			else if(a[c]*t==0){
			}
			
			else a[++c]=t;
		}
		
		
		c++;
		//rep(i,c) cout<<i<<" "<<a[i]<<endl;
		
		//rep(i,c) cin>>a[i];
		MAX=a[0];
		rep(i,c){
			ll sum=0;
			for(int j=i;j<c;j++){
				sum+=a[j];
				MAX=max(MAX,sum);
			}
		}
		
		
		
		/*
		for(int i=1;i<=c;i++){
			rep(j,c+1-i){
				MAX=max(MAX,sum(j,i));
			}
		}
		*/
		cout<<MAX<<endl;
	}
	return 0;
}

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

using namespace std;

int n;
int a[50001];
int S[50001];


int main(){

while(cin >> n && n > 0){


  int max = -100000;
  for (int i = 0; i < n; ++i)
  {
    cin >> a[i];
    if( a[i] > max) max = a[i];
  }

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


  for (int i = 0; i < n + 1; ++i)
  {
    for (int k = 0; k < i ; ++k)
    {
      if(S[i] - S[k] > max) max = S[i] - S[k];
    }
  }

  cout << max << endl;

  }
}