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<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<stack>
#include<set>
#include<cmath>

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

#define EPS 1e-6

using namespace std;

int main(){

   int n,a;
   while(true){
   cin >> n;
   if(n==0) break;

   vector<int>v;
   int s=0;
   v.push_back(s);

   rep(i,n){
   cin >> a;
   s+=a;
   v.push_back(s);
   }

   int vmin=0; int vmax=0;
   rep(i,n){
   if(v[i]<vmin) vmin=v[i];
   if(v[i]>vmax) vmax=v[i];

   }

	cout << vmax-vmin << 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]);
		}*/
		n++;
		vector<int> vec(n),dp(n);
		for(int i=1;i<n;i++)cin >> vec[i];
		//for(int i = 1;i < n;i++)cout << vec[i] << " ";
		dp[0]=0;
		for(int i=1;i<n;i++)dp[i]=max(dp[i-1]+vec[i],vec[i]);
		cout << *max_element(dp.begin()+1, dp.end()) << endl;
	}
	return 0; 
}

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

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

int main(){
  int n ,hoge ,total=0 ,max=0;
  while( true ){
    cin >> n;
    if( !n ){
      break;
    }
    for( int i=0 ; i<n ; i++ ){
      cin >> hoge;
      total += hoge;
      if( total < 0 ) total = 0;
      if( total > max ) max = total;
    }
    cout << max << endl;
    total = 0;
    max = 0;
  }
}

C++: #include <iostream>

using namespace std;

int main()
{
  while(1){
    int n;
    int a[5000];
    cin >> n;
    if(n == 0)
      break;
    else{
      for(int i = 0; i < n; i++)
	cin >> a[i];
      int ans = a[0], num;
      for(int i = 0; i < n; i++){
	num = 0;
	for(int j = i; j < n; j++){
	  num += a[j];
	  ans = (num > ans) ? num : ans;
	}
      }
      cout << ans << endl;
    }
  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define INF=-10000000000000000
int main(void){
    int n,a,max=INF;
    while(std::cin>>n){
        if(n==0) break;
        std::vector<int> dp(n+1);
        dp[0]=INF;
        for(int i=0;i<n;i++){
            std::cin>>a;
            dp[i+1]=(a>0?dp[i]+a:a);
            max=std::max(max,dp[i+1]);
        }
        std::cout<<max<<std::endl;
    
    }
    return 0;
}

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

C++: #include <iostream>

using namespace std;

int main() {
	int n, *a;
	int ans, add;
	while (1) {
		cin >> n;
		if (n == 0)
			break;
		a = new int[n];
		for (int i = 0; i < n; i++)
			cin >> a[i];
		ans = 0;
		for (int i = 0; i < n; i++) {
			add = a[i];
			for (int j = i + 1; j < n; j++) {
				add += a[j];
				ans = max(ans, add);
			}
		}
		cout << ans << endl;
		delete[] a;
	}
	return 0;
}

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

using namespace std;

bool testcase_ends() {
    size_t n;
    scanf("%zu", &n);

    if (!n) return 1;

    vector<int> a(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &a[i]);

    for (size_t i=1; i<n; ++i)
        a[i] += a[i-1];

    vector<int>::iterator min_=min_element(a.begin(), a.end());
    vector<int>::iterator max_=max_element(a.begin(), a.end());
    if (*min_ < 0 && min_ < max_) {
        printf("%d\n", *max_-*min_);
    } else {
        printf("%d\n", *max_);
    }
    return 0;
}

int main() {
    int solved=0;
    while (!testcase_ends())
        ++solved;

    return !solved;
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int n, k, p = 0;
	bool isPlus = true;
	while (cin >> n){
		if (0 == n) break;
		vector<int> A(n, 0);
		int m = INT_MIN;
		for (int i = 0; i < n; ++i){
			cin >> k;
			if (0 == i){
				A[p] = k;
				isPlus = (k > 0);
			} else {
				if (isPlus == (k > 0)){
					A[p] += k;
				} else{
					while (0 != p){
						if (m < A[p - 1]) m = A[p - 1];
						if (m < A[p]) m = A[p];
						if (A[p - 1] + A[p] >= 0){
							A[p - 1] += A[p];
							--p;
							isPlus = true;
						}else break;
					}
					if (isPlus == (k > 0)){
						A[p] += k;
					}else{
						if (m < A[p]) m = A[p];
						++p;
						A[p] = k;
						isPlus = !isPlus;
					}
				}
			}
		}
		if (m < A[p]) m = A[p];
		cout << m << "\n";
		for (int i = 0; i <= p; ++i) A[p] = 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<n;x++){
				kazu=kazu+a[x];
				cout<<kazu<<endl;
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}

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

  for(int n;cin>>n&&n;){
    int a[5000],r;
    cin>>a[0];
    r=a[0];
    for(int i=1,b;i<n;i++){
      cin>>b;
      a[i]=a[i-1]+b;
      r=max(r,a[i]);
    }
    for(int i=0;i<n;i++) for(int j=i;j<n;j++) r=max(r,a[j]-a[i]);
    cout<<r<<endl;
  }
  return 0;
}

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

int main() {
	int n;
	while (std::cin >> n) {
		if (n == 0) break;
		std::vector<int> a;
		int max = 0, left = 0, right = 0, lmin = 0, rmin = 0;
		for (int i = 0; i < n; ++i) {
			int ai;
			std::cin >> ai;
			a.push_back(ai);
			max += ai;
		}
		// ここをかく
		std::vector<int>::iterator leftend = a.begin();
		for (std::vector<int>::iterator itr = a.begin(); itr != a.end(); ++itr) {
			left += *itr;
			if (left < lmin) {
				lmin = left;
				leftend = itr;
			}
		}
		for (std::vector<int>::iterator itr = a.end() - 1; itr != leftend; --itr) {
			right += *itr;
			if (right < rmin) {
				rmin = right;
			}
		}
		max = max - lmin - rmin;
		std::cout << max << std::endl;
	}

	return 0;
}

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

using namespace std;

int N;
long long K[5001],T;

int main()
{
        scanf("%d",&N);
        if (N == 0) return 0;

        T = 0;
        K[0] = 0;

        for (int i=1;i<=N;i++){
                scanf("%lld",K+i);
        }

        for (int i=1;i<=N;i++) {
                K[i] += K[i-1];
        }

        for (int i=0;i<=N;i++) {
                for (int j=i;j<=N;j++) {
                        T = max(T,K[j]-K[i]);
                }
        }

        printf("%lld\n",T);

        main();
}

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;
	while (Num != 0){
		vector<int>	Dat;
		Max = -100002;
		cin >> Num;
		Dat.push_back(-100001);
		FOR(Num){
			cin >> In;
			Dat.push_back(In);
		}
		FORR(1, Num + 1){
			Dat[i] = max(Dat[i], Dat[i - 1] + Dat[i]);
			Max = max(Max, Dat[i]);
		}
		cout << Max << endl;
	}
	return 0;
}