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>
#include <algorithm>

int N = 1 << 17;
int seg[N * 2];

void update(int x, int v) {
    x += N - 1;
    seg[x] = v;
    while (x) {
        x = (x - 1) / 2;
        seg[x] = seg[x + x + 1] + seg[x + x + 2];
    }
}
int query(int a, int b, int x, int l, int r) {
    if (b <= l || r <= a) return 0;
    if (l <= a && b <= r) return seg[x];
    return query(a, b, x + x + 1, l, (l + r) / 2) + query(a, b, x + x + 2, (l + r) / 2, r);
}
int Q(int a, int b) { return query(a, b, 0, 0, N); }

int in() { int x; scanf("%d", &x); return x;}

int main(void)
{
    int n = in(), K = in();
    for (int i = 0; i < n; i++) update(i, in());
    int mini = 1 << 30;
    for (int i = 0; i < n - K; i++) mini = min(mini, Q(i, i + K));
    cout << mini << endl;
    return 0;
}

C++: #include <iostream>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
	int *a, *a2, m, n, t1, t2;
	
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		
		a = (int *)calloc(n-m+1, sizeof(int));
		a2 = (int *)calloc(n, sizeof(int));
		
		for(int i = 0; i < n; i++){
			cin >> t1;
			a2[i] = t1;
		}
		
		for(int i = 0; i < m; i++){
			a[0] += a2[i];
		}
		
		for(int i = 0; i < n-m; i++){
			a[i+1] += (a2[m+i] + a[i] - a2[i]);
		}
		
		sort(a, a+(n-m+1));
		
		cout << a[n-m] << endl;
		
		free(a2);
		free(a);
	}
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n = 0, k = 0;
int a[100001] = {}, b[100001] = {};
int ans;
int main(){
	while (true){
		n = 0; k = 0;
		ans = 0;
		cin >> n >> k;
		if (n == 0 || k == 0)	break;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
		}
		for (int x = 0; x<k; x++){
			b[1] += a[x + 1];
		}
		ans = b[1];
		for (int i = 2; i <= n; i++){
			if (i+k==n+1)	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			ans = max(b[i], ans);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <vector>

using namespace std;

int n,k;
vector<int> v;

int main(){
	int a;
	int i;
	while(scanf("%d %d",&n,&k) && (n || k) ){
		v.clear();
		for(i=0;i<n;i++){
			scanf("%d",&a);
			v.push_back(a);
		}
		a = 0;
		for(i=0;i<k;i++){
			a+=v[i];
		}
		//printf("%d-%d,%d\n",i-k,i,a);
		int max = a;
		for(;i<n;i++){
			a = a - v[i - k] + v[i];
			//printf("%d-%d,%d\n",i-k,i,a);
			if(max < a){max = a;}
		}
		printf("%d\n",max);
	}
}

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

using namespace std;

int a[100000];

int main() {
	int n, k;
	
	while (cin >> n >> k && n != 0) {
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		int sum = 0, ans = 1 << 31;
		for (int l = 0, r = 0; r < n; ++r) {
			if (r - l == k) {
				ans = max(ans, sum);
				sum -= a[l++];
			}
			sum += a[r];
		}
		cout << ans << endl;
	}

	return 0;
}

C++: #include <stdio.h>
int main(){
    long long int n,k,a[1000000],top;
    while(1){
        scanf("%lld%lld",&n,&k);
        if(n==0)return 0;
        scanf("%lld",&a[0]);
        for(int i=1;i<k;i++){
            scanf("%lld",&a[i]);
            a[i]+=a[i-1];
        }
        top=a[k-1];
        for(int i=k;i<n;i++){
            scanf("%lld",&a[i]);
            a[i]+=a[i-1];
            a[i]-=a[i-k];
            if(a[i]>top)top=a[i];
        }
        printf("%lld\n",top);
    }
}

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

using namespace std;

int main() {
  for (;;) {
    int n, k;
    cin >> n >> k;
    if (!n && !k) return 0;
    int a[n];
    long long result = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i < k)
        result += a[i];
    }
    long long sum = result;
    for (int i = k; i < n; i++) {
      sum = sum - a[i-k] + a[i];
      result = max(result, sum);
    }
    cout << result << endl;
  }
}

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

int main(){
  int i,j,n,k,a[100000],s,max;
  while(1){
    cin >> n >> k;
    if(n == 0 && k == 0) break;
    max = 0;

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

    for(i=0;i<n;i++){
      s = a[i];
      for(j=1;j<k;j++){
	if(i + j >= n) break;
	s += a[i+j];
      }
      if(max < s && j == k){
	max = s;
      }
    }

    cout << max << endl;   
  }
  return 0;
}

C++: #include <cstdio>

int main() {
    long n, k;
    for (;;) {
        long a[100002] = {};
        scanf("%ld %ld", &n, &k);
        if (n == 0)
            return 0;
        for (long i = 0; i < n; i++) {
            scanf(" %ld", &a[i]);
        }
        long max = 0;
        for (long i = 0; i < n - k; i++) {
            long result = a[i] + a[i+1] + a[i+2];
            if (result > max)
                max = result;
        }
        printf("%ld\n", max);
    }
}

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

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

  }
  return 0;
}

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

int n, k;
int a[100000];
int ra[100001];	//ra[i] = a[0] + ??? + a[i-1]

int main() {
	while (cin >> n >> k) {
		if (!n) { break; }
		ra[0] = 0;
		for (int i = 0; i < n; i++) {
			ra[i+1] = ra[i] + a[i];
		}

		int ans = -1000000001;
		for (int i = k; i <= n; i++) {
			ans = max(ans, ra[i] - ra[i-k]);
		}

		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
    while(1){
    int n,k;
    cin >> n >> k;
    if(n==0 && k==0){
        break;
    }
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int s=0;
    int m=0;

    while(s+2<n){
        int cm=0;
        for(int j=0; j<k; j++){
            cm+=a[s+j];
        }
    if(cm>m){
        m=cm;
    }
    s++;
    }
    cout << m << endl;
    }
}

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

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n, k;
    int ans = -50000;
    int sum = 0;
    int lastNum;
    vi series;
    cin >> n >> k;

    for(int i=0; i < n; i++){
        int m;
        cin >> m;
        series.push_back(m);

        if(i < k-1) sum += m;
        else {
            sum += m-series[i-3];
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;

}