Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	for true {
		n, k := scanInt(sc), scanInt(sc)
		if n == 0 && k == 0 {
			break
		}
		sum := make([]int, n+2)
		for i := 2; i <= n+1; i++ {
			sum[i] = sum[i-1] + scanInt(sc)
		}
		max := math.MinInt32
		for i := 1; i+k <= n+1; i++ {
			if v := sum[i+k] - sum[i]; max < v {
				max = v
			}
		}
		fmt.Println(max)
	}
	return
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

int data[1001000]={0};

int main(){
    int n,k;
    int sum = -1;
    int tmp,tmp2,tmp3,tmp4;
    while(1){
        cin >> n >> k;
        if(n == 0 && k == 0) break;
        for(int i=0;i<n;i++) cin >> data[i];
        for(int i=0;i<=(n-k)/4;i++){
            tmp = 0;
            tmp2 = 0;
            tmp3 = 0;
            tmp4 = 0;
            for(int j=i,g=n-(i+1),f=(n/2)+i,r=(n/2)-i;j<i+k;j++,g--,f++,r--){
                tmp += data[j];
                tmp2 += data[g];
                tmp3 += data[f];
                tmp4 += data[r];
            }
            if(sum < tmp) sum = tmp;
            else if(sum < tmp2) sum = tmp2;
            else if(sum < tmp3) sum = tmp3;
            else if(sum < tmp4) sum = tmp4;
        }
        cout << sum << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#define ini 0
using namespace std;


int rlay[100001];

int main (){

while (1){
memset(rlay, 0,sizeof(rlay));

int n,k,input,ansmax=0;
cin>>n>>k;
if (n==0&&k==0)break;

rlay[0]=ini;
for (int i=1;i<=n;i++){
        cin>>input;
        rlay[i]=input+rlay[i-1];
}

for (int i=n;i-k>0;i--){
        ansmax = max ( rlay[i]-rlay[i-k] ,ansmax );
}

cout<<ansmax<<endl;

}
return 0;
}

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


int main(){
    int n, k;
    while (cin >> n >> k, n || k){
	vector<int> a;
	vector<int> s;

	int aa;
	for (int i = 0; i < n; i++){
	    cin >> aa;
	    a.push_back(aa);
	    s.push_back(0);
	}
	
	for (int i = 0; i < n - k; i++){
	    for (int j = i; j < i + k; j++){
		s[i] += a[j];
	    }
	}

	sort(s.begin(), s.end(), greater<int>());
	
	cout << s[0] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,k,box[5000]={0},ans=0,sum=0,summ;
int main(){
    cin >> n >> k;
    while(1){
        for(int i=0;i<k;i++){
            cin >> box[i];
            if(box[0]==0&&box[1]==0)break;
            sum+=box[i];
            }
            if(box[0]==0&&box[1]==0)break;
          for(int i=k;i<n;i++){
                cin >> box[i];
                sum+=box[i]-box[i-k];
                if(sum>ans)ans=sum;
        }
    cout << ans <<endl;

    }
    return 0;
}

C++: #include <iostream>

using namespace std;

typedef long long ll;

const int MAX_N = 100000;
int a[MAX_N];

int main() {
  int n, k;
  while (cin >> n >> k) {
    if (n == 0 && k == 0) break;
    ll sum = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i < k) { sum += a[i]; ans = sum; }
      else { sum = sum + a[i] - a[i-k]; ans = max(ans, sum); }
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

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

bool has_key_using_count(map<char, char> &m, char n){
    if (m.count(n) == 0){
		//cout << "m doesn't have " << n << "." << endl;
        return false;
    }
    else{
        //cout << "m has " << n << "." << endl;
        return true;
    }
}

int main()
{
	//ifstream cin("sample.txt");

	int n = 0, k = 0, max = 0, tmp = 0, sumTmp = 0;
	
	vector<int> series, seriesK, sum;

	while (cin >> n >> k) {
		if (n == 0 && k == 0) {
			break;
		}
		series.clear();
		seriesK.clear();
		sum.clear();
		// 読み込み
		//cin >> n >> k;
		rep(i, n) {
			cin >> tmp;
			series.push_back(tmp);
		}

		// 複数のseriesKの最大値を求める
		for (int i = 1; i < n-k+1; i++) {
			seriesK.clear();
			sumTmp = 0;

			// Kまでの数列作成
			for (int j = i; j < i+k; j++) {
				seriesK.push_back(series[j]);
				sumTmp += series[j];
			}

			// 和を求めて格納
			sum.push_back(sumTmp);
		}

		// 和の中で最大のものを出力
		rep(i, sum.size()) {
			if (sum[i] > max) {
				max = sum[i];
			}
		}

		// 出力する
		cout << max << endl;
	}

	return 0;
}

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

#define MAX_N 100000

using namespace std;

int n, k;
int a[MAX_N+1];

int main()
{
	while(true)
	{

	int max_v = 0;
	cin >> n >> k;

	if(n == 0 && k == 0)
	{
		break;
	}

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

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

		for(int j = 0; j < k; j++)
		{
			value += a[i + j];
		}

		max_v = max(max_v, value);
	}	

	cout << max_v << endl;

	}

	return 0;
}

C++: #include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,k;
	while(cin >> n >> k , n){
		int d[100001] = {0};
		for(int i=1;i<=n;i++){
			int t;cin >> t;
			d[i] = d[i-1] + t;
		}
		int ans = 0;
		for(int i=1;i+k-1<=n;i++){
			ans = max(ans,d[i+k-1]-d[i-1]);
		}
		cout << ans << endl;
	}
}

C++: #include <cstdio>

using namespace std;

int n,k,s,smax;
int a[100000];
int s1,s2;

int main(){
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int j=0;j<k;j++) s1+=a[j];
	smax=s1;
	for(int l=0;l<n;l++){
		s2=s1-a[l]+a[n-l];
		if(s1>smax) smax=s1;
		s1=s2;
	}
		printf("%d",smax);
	return 0;
}

C++: #include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower


using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;


int main() {
    int n, k;
    while (1) {
        cin>>n>>k;
        if(n==0){
            break;
        }
        vector<int> a(n);
        rep(i, n)cin >> a[i];
        vector<int> cum(n + 1, 0);
        rep(i, n)cum[i + 1] = cum[i] + a[i];
        ll ans = 0;
        rep(i, n - k) {
            ll cnt = cum[i + k] - cum[i];
            ans = max(ans, cnt);
        }
        cout << ans << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<string.h>
using namespace std;
long long sin[100001];
int main(){
	while(1){
	memset(sin,0,sizeof(sin));
	long n,k;
	int i,j,max=0,x;
		cin>>n>>k;if(n==0&&k==0)break;
	for(i=1;i<=n;i++){
		cin>>sin[i];
	}
	x=0;
	for(j=1;j<=k;j++){
		x+=sin[j];
	}
		for(i=k+1;i<=n;i++){
			x+=sin[i];
			x-=sin[i-k];
			if(x>max)max=x;
		}
		cout<<max<<endl;
	}
	return 0;
}