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<bits/stdc++.h>
using namespace std;
int n,k,box[5000]={0},sum=0,summ;
int main(){
    cin >> n >> k;
    while(1){
        int ans=0;
        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>
#include <deque>

using namespace std;

int main(){
	deque<int> deq;
	int n,k,max,buf;
	
	while(1){
		cin >> n >> k;
		
		if(n || k){
			max = 0;
			
			deq.clear();
			deq.push_front(0);
			for(int i = 0; i < k-1; i++){
				cin >> buf;
				deq.push_front(buf);
				n--;
			}
			
			for(; n > 0; n--){
				cin >> buf;
				deq.push_front(buf);
				deq.pop_back();
				
				buf = 0;
				
				for(int i = 0; i < k; i++){
					buf += deq.at(i);
				}
				
				if(max < buf){
					max = buf;
				}
			}
			
			cout << max << endl;
		}else{
			break;
		}
	}
	
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
ll num[100100];
int main()
{
	while(1)
	{
		int n,k;
		cin >> n >> k;
		if(n==0&&k==0)break;
		memset(num,0,sizeof(num));
		for(int i=1;i<=n;i++)
		{
			int p;
			cin >> p;
			num[i]=p;
		}
		for(int i=2;i<=n;i++)
		{
			num[i]+=num[i-1];
		}
		ll ans=-INF;
		for(int i=1;i<=n-k+1;i++)
		{
			ans=max(ans,num[i+k-1]-num[i-1]);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
    int n, k;
    while (cin >> n >> k, n) {
        vector<int> a(n);
        for (int &ai: a) cin >> ai;
        int sum = 0;
        for (int i = 0; i < k; i++) sum += a[i];
        int ma = sum;
        for (int i = k; i < n; i++) {
            sum += -a[i - k] + a[i];
            ma = max(ma, sum);
        }
        cout << ma << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
long long n, k, a[200000], s, ret;
int main() {
	while (true) {
		cin >> n >> k; if (n == 0)break; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (i <= k)s += a[i]; }
		ret = s; for (int i = k + 1; i <= n; i++) { s -= a[i - k]; s += a[i]; ret = max(ret, s); }
		cout << ret << endl;
	}
	return 0;
}

C++: #include <stdio.h>
int c[100000],d[100000];
int main(){
	int a,b,e,i,j;
	while(1){
	scanf("%d %d",&a,&b);
		if(a==0&&b==0){
			return 0;
		}
	for(i=0;i<a;i++){
		scanf("%d",&c[i]);
	}
	for(i=0;i<a-b+1;i++){
		d[i]=0;
		for(j=i;j<b+i;j++){
			d[i]+=c[j];
		}
	}
	for(i=0;i<a-b+1;i++){
		for(j=0;j<a-b-1;j++){
			if(c[j]<=c[j+1]){
				e=d[j];
				d[j]=d[j+1];
				d[j+1]=e;
			}
		}
	}
	printf("%d\n",d[0]);
	}
	return 0;
}

C++: #include<iostream>
#define INF -10000000
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m){
    if(n==0&&m==0) break;
    int s[n];
    long int ans=INF;
    for(int i=0;i<n;i++) cin >> s[i];
    for(int i=m-1;i<n;i++){
      int su = 0;
      for(int j=i-m+1;j<=i;j++) su += s[j];
      if(ans<su) ans = su;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, k;
        cin >> n >> k;
        if(n == 0)
            return 0;

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

        int sum = 0;
        for(int i=0; i<k; ++i)
            sum += a[i];

        int ret = sum;
        for(int i=0; i<n-k; ++i){
            sum -= a[i];
            sum += a[i+k];
            ret = max(ret, sum);
        }
        cout << ret << endl;
    }
}

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

int n, k;
int t[100002];

int main(){

  while(cin >> n >> k, n || k){
    int sum = 0;

    for(int i = 0; i < n; i++){
      cin >> t[i];
      if(i < k) sum += t[i];
    }

    int ans = sum;

    for(int i = 0; i < n - k; i++){
      sum -= t[i];
      sum += t[i + k];
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
}

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

int main(){
  int serchn,numn;
  int gh = 0;
  int outp = 0;
  for(int a = 0;;a++){
    cin >> numn >> serchn;
    if(numn == 0 && serchn == 0){
      break;
    }
    outp = 0;
    gh = 0;
    vector<int> num(numn);
    for(int n = 0;n<numn;n++){
      cin >> num[n];
    }
    for(int n = 0;n<serchn;n++){
      outp += num[n];
    }
    gh = outp;
    for(int a = 1,b=serchn;a<numn-serchn;a++,b++){
      gh += num[b];
      gh -= num[a];
      if(gh > outp)outp = gh;
    }
    cout << outp << endl;
  }
  return 0;
}

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

#define loop(i,n) for(int i=1;i<=n;i++)
int a[100002];
int s[100002];

int main(){
  while(1){
    int n,k;
    cin>>n>>k;
    if(n==0)return 0;
    loop(i,n)cin>>a[i];
    s[1]=0;
    loop(j,k){
      s[1]+=a[j];
    }
    int m=s[1];
    loop(i,n-k+1){
      if(i==1)continue;
      s[i]=s[i-1]-a[i-1]+a[i+k-1];
      m=max(m,s[i]);
    }
    cout<<m<<endl;
  }
  return 0;
}

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

#define INF (1e+9)
#define LLINF (1e+18)
#define LL long long


using namespace std;


int array[200000];

int main (void){
	//printf("%lld:::%lld",(LL)INF,(LL)LLINF);

	int n;
	int k;

	LL sum;
	LL maxNum;

	while(true){
		sum = 0;
		maxNum = -1*(LL)LLINF;
		scanf("%d",&n);
		scanf("%d",&k);
		if((n==0)||(k==0))break;
		for(int i=0;i<n;i++){
			scanf("%d",array+i);
		}
		for(int i=0;i<k;i++){
			sum += array[i];
		}
		maxNum = max(maxNum,sum);
		for(int i=0;i<n-k;i++){
			maxNum = max(maxNum,sum = (sum-array[i]+array[i+k]));
		}
		printf("%lld\n",maxNum);
	}

	return 0;
}

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

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

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

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

  cout << ans << endl;
}