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>

int main() {
	int n;
	while (std::cin >> n) {
		if (n == 0) break;
		std::vector<int> a;
		for (int i = 0; i < n; i++) {
			int ai;
			std::cin >> ai;
			a.push_back(ai);
		}
		int max = 0, sum = 0;
		std::vector<int>::iterator end = a.begin(), beg = a.begin();
		for (std::vector<int>::iterator itr = a.begin(); itr != a.end(); itr++) {
			sum += *itr;
			if (sum > max) {
				max = sum;
				end = itr;
			}
		}
		sum = max;
		for (std::vector<int>::iterator itr = a.begin(); itr != end; itr++) {
			sum -= *itr;
			if (sum > max) {
				max = sum;
				beg = itr;
			}
		}
		std::cout << max << std::endl;
	}

	return 0;
}

C++: #define scanf_s scanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 50//00
#define MIN -100001
#define _MAX 100
#define ABC 26
int main(void)
{
	int n, a, sum1 = MIN, sum2 = 0, sum3 = 0;
	while (1) {
		scanf_s("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; ++i) {
			scanf_s("%d", &a);
			if (sum1 + a < a) {
				sum1 = a;
				sum2 = a;
			}
			else {
				if (sum1 + a < sum1 || sum2 != sum1) {
					sum2 += a;
				}
				else if (sum1 == sum2) {
					sum1 += a;
					sum2 = sum1;
				}
				if (sum2 > sum1) {
					sum1 = sum2;
				}
			}
		}
		printf("\n%d\n\n", sum1);
		sum1 = sum2 = MIN;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
    int n, ans, sum, x[5000];
    while(1){
        cin >> n;
        if(!n) break;
        ans = -100000;
        for(int i = 0; i < n; i++){
            cin >> x[i];
        }
        for(int i = 0; i < n; i++){
            sum = 0;
            for(int j = 0; j < n; j++){
                sum += x[j];
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
}

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

int main(void){
  int n;
  long a[5000];
  long long max, tmp;

  while(cin >> n && n != 0){
    for(int i = 0; i < n; i++) cin >> a[i];
    max = a[0]; tmp = 0;

    for(int i = 0; i < n; i++){
      for(int j = i; j < n; j++){
        tmp += a[j];
        if(max < tmp) max = tmp;
      }
      tmp = 0;
    }
    cout << max << endl;
  }
  return 0;
}

C++: #include<iostream>

int main(){
  int n;
  int temp,max,a;

  while(1){
    std::cin >> n;
    if(n==0){
      break;
    }
    int a[n];
    for(int i=0;i<n;i++){
      std::cin >> a[i];
    }
    max = a[0];
    for(int i=0;i<n;i++){
      temp = a[i];
      if(max < temp){
        max = temp;
      }
      for(int j=i+1;j<n;j++){
        temp += a[j];
        if(max < temp){
          max = temp;
        }
      }
    }
    std::cout << max << std::endl;
  }
}

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

C++: #include "iostream"
using namespace std;

int a[5000],b[5001];

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		int ma=-1<<30;
		for (int i = 0; i < n; ++i)
		{
			cin>>a[i];
			if (ma<a[i])
			{
				ma=a[i];
			}
		}
		b[0]=0;
	 	for (int i = 0; i < n; ++i)
		{
			b[i+1]=b[i]+a[i];
		}
		for (int i = 1; i <= n; ++i)
		{
			for (int j = 0; i+j <= n; ++j)
			{
				if(ma<b[i+j]-b[j])
				{
					ma=b[i+j]-b[j];
				}
			}
		}
		cout<<max(b[n-1],ma)<<"\n";
	}
	return 0;
}

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

#define MAX 1000000000
#define MIN -10000000000

#define ll long long

using namespace std;
int main() {

        ll n,k,i,j,temp,last,maxx;
        do {
            cin>>n;
            if(n==0)break;
            vector<ll> a(n);
            vector<ll> s(n+1);
            for(i=0;i<n;i++){
                cin>>a[i];
            }
            s[0]=0;
            for(i=0;i<n;i++){
                s[i+1]=s[i]+a[i];
            }
            maxx=-100000;
            for(i=0;i<n;i++){
                for(j=i+1;j<=n;j++){
                    maxx=max(s[j]-s[i],maxx);
                }
            }
            cout << maxx << endl;



        }while(n!=0);

//cout << "aaa" << endl;

    return 0;
}

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

int main(){
	int n;
	while(cin>>n){
		if(!n) break;
		vector<int> all;
		for(int i=0; i<n; i++){
			int buf;
			cin>>buf;
			all.push_back(buf);
		}
		int m = -10000000;
		for(int i=0; i<n; i++){
			int sum = 0;
			for(int j=i; j<n; j++){
				sum += all[j];
				m = max(m, sum);
			}
		}
		cout<<m<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
while(true)
{
int n;
cin >> n;
if(n == 0)return 0;
int* numbers = new int[n];
for(int i = 0;i < n;i++)
cin >> numbers[i];
int max = 0;
for ( int i = 0; i < n; i++){
int sum = 0;
for ( int j = i; j < n; j++){
sum += numbers[j];
if(max < sum)max = sum;
}
}
cout >> max >> endl;
}
}

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) cin>>a[i];
		c=n;
		MAX=a[0];
		rep(i,n){
			ll sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				MAX=max(MAX,sum);
			}
		}
		
		
		/*
		rep(i,n){
			int t;
			cin>>t;
			if(a[c]*t<0){
				a[++c]=t;
			}
			else a[c]+=t;
		}
		
		
		c++;
		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>
using namespace std;
int main(){
	int n, m[10000] = { 0 }, max = 0, temp = 0;
	int out;
	
	while (cin>> n && n!=0){
		for (int i = 0; i < n; i++){
			cin >> m[i];
		}
		for (int i = 0; i < n; i++){
			temp = m[i];
			for (int l = i + 1; l < n; l++){
				temp += m[l];
				if (max < temp){
					max = temp;
				}
			}temp = 0;
		}
		cout << max << endl;
		max = 0;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000],saidai=-100000;
	while(cin>>n&&n!=0){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;n>i;i++){
			int kazu=0;
			for(int x=0;x<=i;x++){
				kazu=kazu+a[x];
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}

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

int main(){
  int n, max_=0, tmp=0, a;
  while(cin >> n){
  for(int i=0; i<n; i++){
    cin >> a;
    tmp = max(0,tmp+a);
    max_ = max(tmp,max_);
  }
  cout << max_ << endl;
  }
  return 0;
}