Go: package main

import "fmt"

func main() {
	var result []int
	for {
		var n, a, maxSum int
		fmt.Scan(&n)

		if n == 0 {
			break
		}

		maxSum = 0
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			if i == 0 {
				sum = a
				maxSum = sum
			} else if sum+a < a {
				sum = a
				if maxSum < sum {
					maxSum = sum
				}
			} else {
				sum = sum + a
				if maxSum < sum {
					maxSum = sum
				}
			}
		}

		result = append(result, maxSum)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}

C++: #include <stdio.h>

int main() {
        int n, a;

        while (true) {
                scanf("%d", &n);
                if (!n) {
                        break;
                }

                long long sum = 0, max = 0;
                for (int i = 0; i < n; i++) {
                        scanf("%d", &a);
                        sum += a;
                        if (sum < 0) {
                                sum = 0;
                        }
                        if (sum > max) {
                                max = sum;
                        }
                }
                printf("%lld\n", max);
        }

        return 0;
}

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

using namespace std;

int main() {
  int input;
  deque<int> datas;
  deque<int> sums;

  cin >> input;
  datas.push_back(input);
  while (cin >> input, input != 0) {
    datas.push_back(input);
    sums.push_back(accumulate(datas.begin(), datas.end(), 0));
    datas.pop_front();
  }

  cout << *max_element(sums.begin(), sums.end()) << endl;

  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		int sum = 0, hold = 0;
		int a;
		bool start = false;
		for(int i = 0;i < n;i++){
			cin >> a;
			if(a > 0) start = true;
			if(start){
				sum += a;
				if(hold < sum){
					hold = sum;
				}
			}
		}
		cout << hold << endl;
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    int n = 0;
    while (cin>>n && n != 0) {
        int a[5001] = {};
        cin>>a[0];
        int max = a[0];
        for (int i = 1; i < n; i++) {
            cin>>a[i];
            if (a[i] >= 0) {
                int temp = 0;
                for (int s = i; s >= 0; s--) {
                    temp += a[s];
                    if (temp > max) max = temp;
                    if (temp < 0) break;
                }
            }
        }
        cout<<max<<endl;
    }
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define HOGE 6000
#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;

int main(){
    int n;
    while(cin>>n){
        int ma=-INF;
        int dp[HOGE][HOGE];
        int data[HOGE];
        if(n==0)break;
        rep(i,n){
            cin>>data[i];
        }
        rep(i,n)dp[i][i]=data[i];
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                dp[i][j]=dp[i][j-1]+data[j];
                ma=max(ma,dp[i][j]);
            }
        }
        cout<<ma<<endl;
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

	int n;
	int a[5000];

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

	return 0;

}

C++: // class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <vector>
#include <queue>


typedef long long llong;
using namespace std;

int main() {
	int n;
	llong maxim;
	int input_num;
	int stock_sum;
	int reserve_max_neg;
	while (1) {
		cin >> n;
		if (!n)break;
		maxim = -100010;
		stock_sum = 0;
		for (int i = 0; i < n; i++) {

			cin >> input_num;
			stock_sum += input_num;
			if (stock_sum > maxim)maxim = stock_sum;
			if (stock_sum < 0)stock_sum = 0;
		}
		cout << maxim << endl;
	}
	return 0;
}

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

int main(){
    int a[5000], n, i, j;
    while (cin >> n && 1 <= n && n <= 5000){
        int maximum = -100000;
        for(i = 0; i < n; i++){
            cin >> a[i];
         }
        for(i = 0; i < n; i++){
            int sum = 0;
            for (j = i; j < n; j++){
                sum += a[j];
                maximum = max(maximum, sum);
            }
        }
        cout << maximum << endl;
    }
}

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

int main(){
	int n;
	int a;
	int sum;
	int sum2;
	int max;
	cin >> n;
	while(n){
		cin >> sum;
		max = -100001;
		for(int i=0;i<n-1;i++){
			cin >> sum2;
			sum += sum2;
			if(sum < sum2){
				sum = sum2;
			}
			if(sum > max){
				max = sum;
			}
		}
		cout << max << endl;
		cin >> n;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int a[n];
		long long int max=0;
		for(int i=0;i<n;i++){
			a[i]=0;
			int input;
			cin>>input;
			for(int j=0;j<=i;j++){
				a[j]+=input;
				if(max<a[j])max=a[j];
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int t[5002];

int main(){
  int n;

  while(cin>>n,n){
    rep(i,n){
      cin>>t[i];
    }

    int ans = INT_MIN;
    rep(i,n){
      int sum = 0;
      REP(j,i,n){
        sum += t[j];
        if(ans < sum){
          ans = sum;
        }
      }
    }

    cout<<ans<<endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(){
    int n,sum,t,i;
    while(cin>>n&&n){
        sum=0;
        for(i=0;i<n;i++){cin>>t;sum+=t;}
        cout<<sum<<endl;
    }
}

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

int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0) break;
    int i,cr,max;
    cr=max=0;
    while(n--){
      cin>>i;
      cr +=i;
      if(cr<0) cr=0;
      if(cr>max) max=cr;
    }
    cout<<max<<endl;
  }
  return 0;
}