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 <vector>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;

int a[1000000];

int main()
{
    int n, k;
    while(cin >> n >> k && n && k) {
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        
        ll pre = 0;
        for(int i = 0; i < k; i++) {
            pre += a[i];
        }
        
        ll ret = pre;
        for(int i = 0; i < n - k; i++) {
            cout << pre << " " << a[i] << " " << a[k + i] << endl;
            pre = pre - a[i] + a[k + i];
            ret = max(ret, pre);
        }
        
        cout << ret << endl;
    }
}

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

int main() {
	while (1) {
		int i, j, n, k, sum = 0, maxsum;

		cin >> n >> k;
		if (n == 0)break;
		int *a = new int[n + 1];
		for (i = 0; i < n; i++) {
			cin >> a[i];
		}

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

		maxsum = sum;

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

		cout << maxsum << endl;
	}
	

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    vector<int> ans(0);
    while(1){
        cin>>n>>k;
        if(n==0&&k==0){
            break;
        }
        vector<int> vec(n);
        for(int i=0;i<n;i++){
            cin>>vec.at(i);
        }
        vector<int> rsw(n+1);
        rsw.at(0)=0;
        for(int i=1;i<n+1;i++){
            rsw.at(i) = rsw.at(i-1) + vec.at(i-1);
        }
        int ans =0;
        for(int i=k;i<n+1;i++){
            if(ans < rsw.at(i) - rsw.at(i-k)){
                ans = rsw.at(i) - rsw.at(i-k);
            }
        }
        cout << ans << endl;
    }
    
}

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

int a[MAX];

int main(void){
 	int n,k;
	cin >> n >> k;
	int ans=-1000000000;
	int cmax=0;
	for(int i=0;i<k;i++){
		cin >> a[i];
		cmax+=a[i];
	}
	ans=max(ans,cmax);
	for(int i=k;i<n;i++){
		cin >> a[i];
		cmax+=a[i];
		cmax-=a[i-k];
		ans=max(ans,cmax);
	}
	cout << ans << endl;
}

C++: #include <iostream>
using namespace std;
int main(void)
{
	for (;;)
	{
		int a,b,c,d,max=0;
		cin>>a>>b;
		int e[a];
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			cin>>d;
			e[c]=d;
		}
		for (int f=0;f<=a-b;f++){
			for (int g=1;g<b;g++){
				e[f]=e[f]+e[f+g];
			}
			if (e[f]>=max) max=e[f];
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

  int in, k;

  while(cin >> in >> k){
    if(in == 0 && k == 0) break;
    int data[in];
    int sum;

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

   

    for(int i = 0; i <= in-k; i++){
      int tmp = 0; 
      for(int j = i; j < i+k; j++){
	tmp += data[j];
      }
      if(i == 0 || sum < tmp) sum = tmp;
    }

    cout << sum << endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;



const int mod = 100000;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const long long  int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}

#define MAX_MOD_N 1024000

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init(const int amax = MAX_MOD_N) {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < amax - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}

int main() {
	while (1) {
		int N, K; cin >> N >> K;
		if (!N)break;
		vector<int>as(N);
		for (int i = 0; i < N; ++i) {
			cin >> as[i];
		}
		long long int sum = 0;
		for (int i = 0; i < K; ++i) {
			sum += as[i];
		}
		long long int ans = sum;
		for (int i = K; i < N; ++i) {
			sum += as[i] - as[i - K];
			ans = max(ans, sum);
		}
		cout << ans << endl;
	}

	return 0;
}

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

int max(int a, int b){
	if(a > b) return a;
	else return b;
}

int main(){
	const int MAX_N = 100000;
	int n, a[MAX_N], k, S, S1, S2;
	int p;
	
	while(true){
		scanf("%d%d", &n, &k);
		if(n == 0 && k == 0) break;
		for(int i = 0; i < n; i++) scanf("%d", &a[i]);
		
		S = 0;
		for(p = 0; p < k; p++){
			S += a[p];
		}
		S1 = S;
		
		while(p < n){
			S2 = S1 + a[p] - a[p - k];
			
			S = max(S, S2);
			
			S1 = S2;
			
			p++;
		}
		
		printf("%d\n", S);
	}
	
	return 0;
}

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

int main(){
  int n,k,a,s;
  while(cin>>n>>k,n||k){
    int m=-10001;a=0;
    queue<int> q;
    n-=k;
    while(k--){
      cin>>s;
      a+=s;q.push(s);
    }
    m=max(m,a);
    while(n--){
      cin>>s;
      q.push(s);
      a=a+s-q.front();
      q.pop();
      m=(m>a)?m:a;
    }
    cout<<m<<endl;
  }
  return 0;
}