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<algorithm>

using namespace std;

#define FOR(a) for(int i = 0; i < a; i++)
#define FORR(a, b) for(int i = a; i < b; i++)

int main(void){
	int Max, Num = -1, In;
	vector<int>	Dat;
	while (Num != 0){
		Max = -100000;
		cin >> Num;
		FOR(Num){
			cin >> In;
			Dat.push_back(In);
		}
		FORR(1, Num){
			Dat[i] = max(Dat[i], Dat[i - 1] + Dat[i]);
			Max = max(Max, Dat[i]);
		}
		cout << Max << endl;
	}
	return 0;
}

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

int main() {
	int n;
	long long sum, max;

	while (true) {
		sum = max = 0;
		cin >> n;
		if (n == 0) break;

		int a[n];

		for (int i = 0; i < n; i++)
			cin >> a[i];

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

		cout << max << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(void)
{
    int a[5000], n, ans, sum;
    
    while(true)
    {
        cin >> n;
        if(n == 0) break;
        rep(i,n)
            cin >> a[i];
        
        ans = a[0];
        rep(i,n)
        {
            sum = 0;
            for(int j=i; j<n; j++)
            {
                sum += a[j];
                ans = max(ans, sum);
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int N;
        cin>>N;
        if(!N)break;
        int rui[10000]={0};
        for(int i=1;i<=N;i++){
            int a;
            cin>>a;
            rui[i]=rui[i-1]+a;
        }
        int ans=-2000000000;
        //for(int i=0;i<=N;i++)printf("[%d]",rui[i]);
        for(int i=0;i<=N;i++){
            for(int j=i;j<=N;j++)ans=max(ans,rui[j]-rui[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

void saiki(int num,int sum);

int term[10000],n,ans;

int main(void)
{
   while(scanf("%d",&n))
   {
      ans = -100000000;
      if(n == 0) break;
      for(int i = 0;i < n;i++) scanf("%d",&term[i]);
      for(int i = 0;i < n;i++) saiki(i+1,term[i]);

      printf("%d\n",ans);
   }
   return 0;
}

void saiki(int num,int sum)
{
   if(ans < sum) ans = sum;
   if(num >= n) return;
   saiki(num+1,sum+term[num]);

}

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

int a[5000] = {0};
int S[5000] = {0};

int main() {
  int n;
  while(cin >> n) {
  if(n == 0) break;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }

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

  int maxsum = 0;
  int sum = 0;
  for(int i = 0; i <= n-1; i++){
    for(int j = i + 1; j <= n;j++) {
      sum = S[j] - S[i];
      if(sum > maxsum)
	maxsum = sum;
      sum = 0;
    }
  }
  cout << maxsum << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(void){

	long n, max=0;
	long *a;
	long sum;

	do{
		max = 0;
		//cout << endl;
		cin >> n;

		if (n == 0) break;

		a = new long[n + 1];

		sum = 0;

		for (int i = 0; i < n; i++){

			sum = 0;

			cin >> a[i];

			for (int j = i; j >= 0; j--){

				sum += a[j];
				if (max < sum) max = sum;
			}
		}

		cout << max << endl;
	} while (1);
}

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

int kadaneAlg(int arr[], const int &len) {
    int max_global;
    int max_current = max_global = arr[0];

    for (int i = 1; i < len; i++) {
        max_current = std::max(arr[i], arr[i] + max_current);
        if (max_current > max_global) max_global = max_current;
    }
    return max_global;
}

int main()
{
    int N;
    while(1) {
        std::scanf("%d", &N);
        if (N == 0) break;
        int arr[N];
        for (int i = 0; i < N; i++) scanf("%d", &arr[i]);
        std::printf("%d\n", kadaneAlg(arr, N));
    }
    return 0;
}

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

int main(){

  int n,count,maxu;

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

    int numbers[n];
    for(int i=0;i<n;i++)
      cin >> numbers[i];
    maxu = 0;

    for(int i=n-1;0<=i;i--){
      for(int j=0;i+j<n;j++){
	count = 0;
	for(int k=j;k<=j+i;k++)
	  count += numbers[k];
	maxu = max(maxu,count);
      }
    }
    cout << maxu << endl;

  }

  return 0;
}

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

using namespace std;

int main(){
  int n,x[5000];
  while(1){

  cin >> n;
  if(n==0)break;

  for(int i=0; i < n;i++)cin >> x[i];

  int now=0;
  int Max=-100001,tmp;
  for(int i = 0;i < n; i++){
    now+=x[i];
    tmp=now;

    for(int j=0;j < i;j++){
      Max=max(Max,now);
      now-=x[j];
      }

    now=tmp;
    }
  cout << Max << endl;
} 

  return 0;
}

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

using namespace std;

int main(){
  int n,x[5000];
  while(1){

  cin >> n;
  if(n==0)break;

  for(int i=0; i < n;i++)cin >> x[i];

  int now=0;
  int Max=-100001,tmp;
  for(int i = 0;i < n; i++){
    now+=x[i];
    tmp=now;

    for(int j=0;j < i;j++){
      Max=max(Max,now);
      now-=x[j];
      }

    now=tmp;
    }
  cout << Max << endl;
} 

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define in        []{int n; cin>>n; return n;}()

int main() {
    int N = in;
    if( !N ) return 0;
    vector<int> A(N+1, 0);
    rep( i, N ) A[i+1] = in + A[i];
    int ans = INT_MIN;
    rep( r, N+1 ) rep( l, r ) ans = max( ans, A[r] - A[l] );
    cout << ans << "\n";
    main();
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;

int main(void){
    for(int n, res, sum; cin >> n, n; cout << res << endl){
        res = sum = 0;
        while(n --){
            int a; cin >> a;

            sum += a;
            if(sum < 0){
                sum = 0;
                if(res < a) res = a;
            }
            else
                if(res < sum) res = sum;
        }
    }

    return 0;
}

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

using namespace std;

int main(){

  int n;


  while(cin >> n){
    if(n == 0) break;
    vector<int> V;
    int status = 1;
    int in;
    int sum = 0;
    for(int i = 0; i < n; i++){
      cin >> in;
      if(i == 0){
	if(in < 0) status = -1;
	else if(in > 0)status = 1;
	else V.push_back(0);


      } else {
	if(in == 0) V.push_back(0);

	if(in < 0 && status == 1){
	  status = -1;
	  V.push_back(sum);
	  sum = 0;
	}else if(in > 0 && status == -1){
	  status = 1;
	  V.push_back(sum);
	  sum = 0;
	}
      }
      sum += in;
    }

    V.push_back(sum);

    int max = -700000000;
    
    for(int i = 0; i < V.size(); i++){
      sum = 0;
      for(int j = i; j < V.size(); j++){
	sum += V[j];
	if(max < sum) max = sum;
      }
    }
    
    cout << max << endl;
  }
  return 0;
}