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 <cstdio>
int n,k;
int main(void){
  scanf("%d%d",&n,&k);
  while(n!=0){
    int i;
    int mem[100000]={0};
    for(i=0;i<n;i++){
      scanf("%d",&(mem[i]));
    }
    int ans=0;
    int now=0;
    for(i=0;i<k;i++){
      now+=mem[i];
      ans=now;
    }
    for(i=0;i+k<n;i++){
      now-=mem[i];
      now+=mem[i+k];
      ans=(ans<now)?now:ans;
    }
    printf("%d",ans);
    scanf("%d%d",&n,&k);
  }
  return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n,k;
    while(cin>>n>>k,n+k){
    vl dp;
    vl sum(n,0);
    rep(i,n){
        ll ujimatu; cin>>ujimatu;
        dp.push_back(ujimatu);
        if(!i)sum[i]=ujimatu;
        else if(i<k)sum[i]+=sum[i-1]+ujimatu;
        else sum[i]=ujimatu+sum[i-1]-dp[i-k];
        
    }
    ll ans=-INF*INF;
    rep(i,n)cmax(ans,sum[i]);
    //rep(i,n)cout<<sum[i]<<endl;
    cout<<ans<<endl;
    }
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int n,a[100001],k,sum,p;
int main(){
int i,j,h;
cin>>n>>k;
for(i=1;i<=n;i++){
a[i]=0;
}
cin>>a[1];
for(i=2;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
for(i=1;i<=n;i++){
	for(j=i;i<=i+k;j++){
		p=a[i+k]-a[j];
		if(p>=sum){
			sum=p;
		}
	}
}
cout<<sum<<endl;
return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
int 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++: // 基本テンプレート
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int acc[100010];
signed main() {
    int N, K;
    while(cin >> N >> K, N || K) {
        memset(acc, 0, sizeof(acc));
        for(int i=0; i<N; i++) {
            cin >> acc[i+1];
            acc[i+1] += acc[i];
        }

        int ans = -INF;
        for(int i=K; i<=N; i++) {
            chmax(ans, acc[i] - acc[i-K]);
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>

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

int main(){

	int n,k,s,data;
	s = 0;
	
	while(cin >> n >> k, n && k){
	vector<int> sum;	

	rep(i,n){
		cin >> data;
		sum.push_back(data);
	}
	
	data = 0;

	rep(i,k){

		data += sum[i];
		
	}

	int res;
	res = data;
	
	rep(i,n - k){
		data -= sum[i];
		data += sum[i+k];
		res = max(res,data);
	}

	cout << res << endl;
	}
	
	return 0;
}

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

int main(){
	int n, k, a[100000] = {};
	long long int sum = -10000000, tmp;
	while(cin >> n >> k){
		if(n == 0 && k == 0) break;
		tmp = 0;
		for(int i = 0;i<n;i++){
			cin >> a[i];
			if(i < k) tmp += a[i];
		}
		for(int i = 0;i + k<n;i++){
			if(sum < tmp) sum = tmp;
			tmp = tmp - a[i] + a[i+k];
		}
		cout << sum << endl;
	}
	return 0;
}

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

using namespace std;






int main() {

	
	int nsize;
	int ksize;
	int a[100000];


	while (true) {
		cin >> nsize >> ksize;
		if (nsize == 0 && ksize == 0)break;
		for (int i = 0; i < nsize; i++) {
			cin >> a[i];
		}
		int maxval;
		int val = 0;
		for (int i = 0; i < ksize; i++) {
			val += a[i];
		}
		maxval = val;

		for (int i = ksize; i < nsize; i++) {
			val -= a[i - ksize];
			val += a[i];
			if (maxval < val) {
				maxval = val;
			}
		}
		cout << maxval << endl;
	}
	






	
	
	//system("pause");
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const ll INF = 1 << 30;
// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

class BIT{
public:    
    BIT(){}
    BIT(int n){
        init(n);
    }
    void init(int n){
        size = n;
        FOR(i, 1, size+1){
            data[i] = 0;
        }
    }
    void add(int k, int v){
        while(k <= size){
            data[k] += v;
            k += k & -k;
        }
    }
    ll sum(int k){
        int sum = 0;
        while(k > 0){
            sum += data[k];
            k -= k & -k;
        }
        return sum;
    }
private:
    static const int MAX_N = 100001;
    ll data[MAX_N];
    int size;
};

int N, K;
BIT bit;

int main(){
    while(std::cin >> N >> K, N){
        bit.init(N);

        FOR(i, 1, N+1){
            int n;
            std::cin >> n;

            bit.add(i, n);
        }

        ll res = -INF;
        FOR(i, 1, N+1){
            if(i+K-1 <= N){
                res = std::max(res, bit.sum(i+K-1) - bit.sum(i-1));
            }
        }

        std::cout << res << std::endl;
    }
}