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

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

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

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

  int maxsum = 0;
  int sum;
  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;
    }
  }
  cout << maxsum << endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define INF=-10000000000000000000
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;
    
    }
    retrn 0;
}

C++: // 0022.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(int a=0;a<t;a++) 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while (cin >> n) {
		int sum[5001];
		roop(i, n) {
			cin >> sum[i];
			if (i != 0) { sum[i] += sum[i - 1]; }
		}
		int ans = -9000000000;
		for (int i = -1; i < n-1; i++) {
			int	sumi = 0;
			if (i != -1)
			{
				sumi = sum[i];
			}
			for (int j = i + 1; j < n; j++) {

				int sumj = sum[j];
				ans = max(ans, sumj - sumi);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
	int n;
	while(cin >> n, n){
		vector<int> vec;
		for(int i = 0; i < n; i++){
			int a;
			cin >> a;
			vec.push_back(a);
		}

		int max = vec[0] + vec[1];
		for(int i = 0; i < vec.size(); i++){
			int add = 0;
			for(int j = i; j < vec.size(); j++){
				add += vec[j];
				if(max < add) max = add;
			}
		}

		cout << max << endl;
	}
}

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

int main(){
  int n;
  cin >> n;
  while(n!=0){
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a.at(i);

    vector<int> s(n+1);
    s.at(0) = 0;
    for(int i=1;i<n+1;i++) s.at(i) = s.at(i-1)+a.at(i-1);

    int ans= -1000000000;
    for(int i=1;i<n+1;i++){
      for(int j=0;j<i;j++){
        ans = max(s.at(i)-s.at(j),ans);
      }
    }

    cout << ans << endl;

    cin >> n;
  }
}

C++: #include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
using namespace std;
 
int main() {
    while(true) {
        int n; scanf("%d", &n);
        if(n==0) break;
        int submax; scanf("%d", &submax);
        int maxval = submax;
        for(int i = 1; i < n; i++) {
            int a; scanf("%d", &a);
            submax = max(a, submax+a);
            maxval = max(maxval, submax);
        }
        printf("%d\n", maxval);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(int argc, const char * argv[])
{
    while (1) {
        int n;
        scanf("%d", &n);
        if (n == 0) {
            break;
        }
        int a[n], b[n], tmp = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
            b[i] = 0;
        }
        for (int i = 0; i < n; i++) {
            for (int k = 0; k <= i; k++) {
                b[i] += a[k];
            }
        }
        for (int i = n-1; i > 0; i--) {
            for (int k = i-1; k >= 0; k--) {
                if (i == n-1) {
                    tmp = (b[i] - b[k] + a[k]);
                }
                if (tmp < (b[i] - b[k] + a[k])) {
                    tmp = (b[i] - b[k] + a[k]);
                }
            }
        }
//        //debug
//        for (int i = 0; i < n; i++) {
//            printf("%d ", a[i]);
//        }
//        puts("");
//        for (int i = 0; i < n; i++) {
//            printf("%d ", b[i]);
//        }
//        puts("");
        cout << tmp << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int n, k, p, m;
	bool isPlus = true;
	while (cin >> n){
		if (0 == n) break;
		vector<int> A(n, 0);
		m = INT_MIN;
		p = 0;
		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{
					++p;
					A[p] = k;
					isPlus = !isPlus;

					while (1 < p && isPlus){
						if (m < A[p - 2]) m = A[p - 2];
						if (m < A[p]) m = A[p];
						int a = A[p - 2] + A[p - 1] + A[p];
						if ((a > A[p - 2]) && (a > A[p])){
							A[p - 2] += A[p-1] + A[p];
							A[p - 1] = A[p] = 0;
							p -= 2;
						}
						else break;
					}
				}
				if (m < A[p]) m = A[p];
			}
		}
		if (m < A[p]) m = A[p];
		cout << m << "\n";
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

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

int main() {
  int n, a[5010], sum[5010], res;
  while (true) {
    cin >> n;
    if (n == 0) break;
    rep (i, n) cin >> a[i];
    sum[0] = 0;
    rep (i, n) sum[i + 1] = a[i] + sum[i];
    res = 0;
    rep (i, n) rep (j, i) {
      res = max(res, sum[i + 1] - sum[j]);
    }
    cout << res << endl;
  }
}

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

int main()
{
    while(1){
        int n;
        cin >> n;
        if( !n ) break;
        
        int a;
        int sum=0, max=numeric_limits<int>::min();
        for(int i=0; i<n; i++){
            cin >> a;
            
            if( a<=0 && sum<=0) continue;
            else sum += a;

            if( sum > max ) max = sum;
        }
        cout << max << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int main()
{
	int n;
	while(true)
	{
		scanf("%d",&n);
		if(n==0){return 0;}
		
		if( n >= 1 && n <= 5000){
		int a[5000]={0},max=0;
		for(int x=0;x<n;x++)
		{
			scanf("%d",&a[x]);
			if(a[x]>=10000||a[x]<=-100000)
			{
				x--;
			}
			else
			{
			for(int y=0;y<=x;y++)
			{
				if(y!=x)
				{
					a[y]+=a[x];
				}
				if(max<a[y])
				{
					max=a[y];
				}
			}
			}
		}
		printf("%d\n",max);
		}
	}
}

C++: #include <iostream>
using namespace std;
int main(){
	for (;;){
		int a,goukei=0,max=0,b;
		cin>>a;
		if (a==0)break;
		int data[a+1]={0};
		for (int A=1;A<=a;A++){
			cin>>data[A];
			if (max<data[A])max=data[A];
			goukei+=data[A];
			data[A]=goukei;
			if (max<data[A])max=data[A];
		}
		for (int A=3;A<a;A++){
			b=A-2;
			for (int B=b;B>0;B--){
				goukei=0;
				goukei=data[A]-data[B];
				if (goukei>max) max=goukei;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,a[5000]={0},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+1;x++){
				kazu=a[i]+a[x+1];
				cout<<kazu<<endl;
				if(kazu>saidai){
					saidai=kazu;
				}
			}
		}
		cout<<saidai<<endl;
	}
}