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 <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

int N,K;
vector<int> a;
vector<int> sum;

int main() {
  while(cin >> N,cin >> K) {
    if(N==0&&K==0) break;
    a.resize(N);
    sum.resize(N+1);
    sum[0] = 0;
    rep(i,N) {
      cin >> a[i];
      sum[i+1] = a[i] + sum[i];
    }
    ll ans = 0;
    rep(i,N-K) {
      ll tmp = sum[i+K] - sum[i];
      ans = max(ans,tmp);
    }
    cout << ans << endl;
  }
}

C++: #include<iostream>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))for(M=1<<31,i=s=0;i<n;s+=a[i++],k<i&&(s-=a[i-k-1]),M<s&&(M=s))std::cin>>a[i];}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    while (cin >> n >> k, n) {
        int sum = 0, res = -INT_MAX;
        vector<int> v(n, 0);
        for (int i=0; i<n; ++i) {
            cin >> v[i];
            sum += v[i] - (k <= i ? v[i-k] : 0);
            res = max(res, (k-1 <= i ? sum : -INT_MAX));
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
	long long n, k, a[100005] = { 0 }, sum[100005] = { 0 }, m = -299999;
	cin >> n >> k;
	if (n == 0 && k == 0) return 0;
	for (int i = 0; i < n; i++) cin >> a[i];
	sum[0] = a[0] + a[1] + a[2];
	for (int i = 1; i < n-2; i++) {
		sum[i] = sum[i - 1] + a[i + 2] - a[i - 1];
	}
	for (int i = 0; i < n - 2; i++) {
		cout << sum[i] << endl;
		if (m < sum[i]) {
			m = sum[i];
		}
	}
	cout << m << endl;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<vector>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define sint(n) scanf("%d",&n)

using namespace std;


int main(){
	while(1){
		int n,k;
		sint(n);
		sint(k);
		
		if(n==0) break;
		
		int kazu[100000];
		rep(i,n) sint(kazu[i]);
		
		int syoki=0;
		
		rep(i,k) syoki+=kazu[i];
		
		int maxi=syoki;
		rep(i,n-k){
			syoki-=kazu[i];
			syoki+=kazu[i+k];
			maxi=max(syoki,maxi);
		}
		
		printf("%d\n",maxi);
	}
}

C++: #include<iostream>
#include<string.h>
using namespace std;
int main(){
	int i,i2,n,k,a[5001],max=0,sum;
	cin>>n>>k;
	while(n!=0){
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=n-k+1;i++){
		sum=0;
		for(i2=i;i2<i+k;i2++)sum+=a[i2];
		if(sum>max){
			max=sum;
		}
	}
	cout<<max<<endl;
	cin>>n>>k;
	}
}

C++: #include <stdio.h>
int main(){
while(1){
int k,n,i,x[100000];
long long int max,sum=0;
scanf("%d%d",&n,&k);
if(n==0 && k==0) break;
for(i=0;<n;i++){
scanf("%d",&x[i]);
}
for(i=0;i<k;i++){
sum+=x[i];
}
max=sum;
for(i=1;i<=n-k;i++){
for(j=i;j<i+k;j++){
sum=0;
sum+=x[j];
}
if(max<sum) max=sum;
}
printf("%lld\n",max);
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);
    }
    int ans = 0;
    int total = 0;
    for(int i = 0; i < N; i++){
    	if(i < k) total += a[i];
	    else total = total + a[i] - a[i-k];
	    if(ans < total) ans = total;
    }
    cout << ans << endl;
}

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);
    }
    int ans = 0;
    int total = 0;
    for(int i = 0; i < N; i++){
    	if(i < k) total += a[i];
	    else{
	        total = total + a[i] - a[i-k];
	        if(ans < total) ans = total;
	    }
    }
    cout << ans << endl;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;

int main(){
    int n,k;
    while(cin>>n>>k&&n&&k){
        vector<int> v(n+1,0);
        rep(i,0,n){
            cin>>v[i+1];
            if(i)v[i+1]+=v[i];
        }

        int ans=0;
        rep(i,k+1,n+1){
            ans=max(ans,v[i]-v[i-k]);
        }
        cout<<ans<<endl;
    }

    
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<functional>
#include<cstring>
using namespace std;
int main() {
	int n,k;
	int num[100001] = {0};
	while(scanf("%d%d",&n,&k),(n|k)){
		memset(num,0,sizeof(num));
		for(int i = 0; i < n; i++){
			scanf("%d",&num[i]);
		}
		int sum = 0;
		for(int i = 0; i < k; i++){
			sum += num[i];
		}
		int tmp = sum;
		for(int i = k; i < n; i++){
			tmp += num[i];
			tmp -= num[i-k];
			sum = max(sum,tmp);
		}
		printf("%d\n",sum);
	}
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値

int main() {
    // 入力
    int N, K;
    while (cin >> N >> K) {
        if (N == 0) break;
        vector<long long> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i];
        
        // 累積和を前計算
        vector<int> s(N+1, 0);
        for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];
        
        // 答えを求める
        long long res = -INF; // 最初は無限小の値に初期化しておく
        for (int i = 0; i <= N-K; ++i) {
            long long val = s[K+i] - s[i];
            if (res < val) res = val;
        }
        cout << res << endl;
    }
}

C++: 
#include<iostream>
main(){
  for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M)){
    for(M=1<<31,i=s=0;i<n;s+=a[i]-(k<=i)*a[i-k],(k<++i)&&(M<s)&&(M=s)){
      std::cin>>a[i];
    }
  }
}