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<stdio.h>
#include <iostream>
#include<bits/stdc++.h> 

using namespace std;
int length=0;
int* sums;

int main(){
  label:
  cin>>length;
  if(length==0)return 0;
  sums=new int[length];
  
  int s=0;
  for(int i=0;i<length;i++){
    int v=0;
    cin>>v;
    s+=v;
    sums[i]=s;
  }
  int max=INT_MIN;
  for(int i=0;i<length;i++){
    for(int j=i+1;j<length;j++){
      int diff=sums[j]-sums[i];
      if(diff>max){
        max=diff;
      }
    }
  }
  cout<<max;
  cout<<"\n";
  goto label;
  return 0;
}

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

int main(void){
	int N;
	while (cin >> N, N) {
		vector<int> a(N);
		for (int i = 0; i < N; i++)
			cin >> a[i];
		vector<int> sums;
		sums.push_back(0);
		partial_sum(a.begin(), a.end(), back_inserter(sums));

		int m = INT_MIN;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				m = max(m, sums[j + 1] - sums[i]);
			}
		}

		cout << m << endl;
	}
}

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

int main(){
  while(true){
    int n, max=0, tmp=0;
    cin>>n;
    if(n==0)break;
    for(int i=0; i<n; i++){
      int d;
      cin>>d;
      tmp=(tmp>0 ? tmp+d : d);
      if(max<tmp)max=tmp;
    }
    cout<<max<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int a[5000];
int main(){
int n;
while(true){
cin>>n;
if(n==0)
break;
long long best=-1000000000;
for(int i=0;i<n;i++)
 cin>>a[i];
 
for(int start=0;start<n;start++){
 long long count=0;
 for(int len=start;len<n;len++){
  count+=a[len];
  best=max(best,count);
 }
}

cout<<best<<endl;
}
return 0;   
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
long long dp[6000],n,a,i,maxm;
int main(){
  while(1){
    cin>>n;
    maxm=-999999999;
    if(n==0)break;
    cin>>a;
    dp[1]=maxm=a;
    for(int i=2;i<=n;i++){
      cin>>a;
      dp[i]=dp[i-1]+a;
      if(dp[i]<0)dp[i]=0;
      maxm=max(dp[i],maxm);
    }
    cout<<maxm<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int n, i, k;
    int data[5000];
    while (cin >> n) {
        if (n == 0) {
            break;
        }
        int pdata [5001] = {0};
        int result = 0;
        for (i = 0; i < n; i++) {
            cin >> data[i];
        }
        for (i = 0; i < n; i++) {
            pdata[i + 1] = pdata[i] + data[i];
        }
        for (i = 0; i < n + 1; i++) {
            for (k = 0;  k < n + 1; k++) {
                if (result < pdata[i + k] - pdata[i]) {
                    result = pdata[i + k] - pdata[i];
                }
            }
        }
        cout << result << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int num;

	while( cin >> num ) {
		if (num == 0 )
			break;

		long int tmpsum = 0;
		long int currnum;
		long int maxnum = -999999999;
		for( int i = 0; i < num; i++ ) {
			cin >> currnum;

			if( currnum + tmpsum > maxnum ) {
				maxnum = currnum + tmpsum;
			}
			
			if( currnum + tmpsum > 0 )
				tmpsum += currnum;
			else
				tmpsum = 0;
		}
		cout << maxnum << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
  while(1){
    int n;
    scanf("%d", &n);
    if(n==0){
      break;
    }

    int a[5000];
    int max;

    int i,j,k;
    for(i=0; i<n; ++i){
      scanf("%d", &a[i]);
      int sum = 0;
      for(j=i; j>=0; --j){
        sum += a[j];
      }
      if((i==0 && j==0) || sum>max){
        max = sum;
      }
    }

    printf("%d\n", max);
  }

  return 0;
}

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

using namespace std;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		vector<int> Vec(N);
		for(int i = 0; i < N; ++i)
		{
			cin >> Vec[i];
		}
		int Max = -999999999;
		for(int i = 0; i < N; ++i)
		{
			int sum = 0;
			for(int j = i; j < N; ++j)
			{
				sum += Vec[j];
				if(sum > Max)
				{
					Max = sum;
				}
			}
		}
		cout << Max << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n,x[5001],sum=0,maxx=0;
        cin>>n;
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            cin>>x[i];
        }
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                sum+=x[j];
                maxx=max(maxx,sum);
            }
            sum=0;
        }
        cout<<maxx<<endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,a[5001],s,m;
	while(1){
		cin>>n;
		if(!n)break;
		for(int i=0;i<n;i++)cin>>a[i];
		m=-10000000;
		for(int i=0;i<n;i++){
			s=0;
			for(int j=i;j>=0;j--){
				s+=a[j];
				if(s>m)m=s;
			}
		}
		cout<<m<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int gets(int d){
	return d >= 0 ? 1 : -1;
}

int seqsum(int n){
	int a[5000];
	int b[5000];
	int c = 0;
	int s = 0;

	scanf("%d", a);
	b[0] = a[0];
	s = gets(a[0]);

	for(int i=1; i<n; ++i){
		scanf("%d", a+i);
		if(s == gets(a[i])){
			b[c] += a[i];
		}else{
			b[++c] = a[i];
			s = gets(a[i]);
		}
	}

	int m = b[0];
	int sum = m;
	if(c == 0){
		if(m >= 0){ return m; }
		m = a[0];
		for(int i=1; i<n; ++i){
			if(m < a[i]){
				m = a[i];
			}
		}
		return m;
	}
	for(int i=1; i<=c; ++i){
		if(m < sum + b[i]){
			sum += b[i];
			m = sum;
		}else if(m < b[i]){
			sum = m = b[i];
		}else{
			sum += b[i];
		}
	}

	return m;
}

int main(void){
	int n = 0;
	while(true){
		scanf("%d", &n);
		if(n == 0){ break;}
		printf("%d\n", seqsum(n));
	}
	return 0;
}

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

int main()
{
    for (int n; cin >> n && n;) {
        vector<int> sequence(n);
        int sum = 0;
        int max_val = numeric_limits<int>::min();
        for (int x, i = 0; i < n && cin >> x; i++) {
            if (sum < 0)
                sum = x;
            else
                sum += x;
            max_val = max(max_val, sum);
        }
        cout << max_val << endl;
    }

    return 0;
}

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

int main()
{
	int n=1, count = 0;
	int a[10000];
	while (n != 0) {
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = -10000;
		for (int ai = 0; ai < n - 1; ai++) {
			sum = 0;
			for (int bi = ai; bi < n; bi++) {
				sum = sum + a[bi];
				if (sum > max) {
					max = sum;
				}
			}
		}
		if (n != 0)
			cout << max << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<int> a,b;
    for(int i=0,j; i<n; i++){
      cin >>j;
      a.push_back(j);
      if(i != 0) a[i]+=a[i-1];
    }
    b.push_back(0);
    for(int i=1; i<n; i++) b.push_back(min(b[i-1],a[i]));
    int ans = a[0];
    for(int i=1; i<n; i++) ans = max(ans,a[i]-b[i-1]);
    cout <<ans<<endl;
  }
  return 0;
}