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

using namespace std;

int main(){
	while (1){
		int n, k;
		int b[100000] = {};
		scanf("%d%d", &n, &k);
		if (n == 0 && k == 0)return 0;
		int base = 0;
		for (int i = 0; i < k; i++){
			int a;
			scanf("%d", &a);
			b[i] = a;
			base += a;
		}
		int sa = 0,ans = 0;
		for (int i = k; i < n; i++){
			int c;
			scanf("%d", &c);
			sa += c - b[0];
			ans = max(ans,sa);
			for (int j = k-1; j > 0; j--){
				b[j-1] = b[j];
			}
			b[k-1] = c;
		}
		printf("%d\n", ans + base);
	}
}

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

using namespace std;

int main(){
  int n,k;
  int sum1=0 , max = 0;
  int now = 0, nextdata, next;
  int* s;
  while(1){
    sum1 = 0;
    max = 0;
    cin >>n >>k;

    if(n == 0) break;

    s = (int*)malloc(sizeof(int) * k);

    int data;
    for(int i = 0; i<k; i++){
      cin >>data;
      s[i] = data;
      sum1 += data;
    }
    max = sum1;
    now = n-1;

    for(int i = 0; i<n-k; i++){
      cin >>data;
      if(now+1 == n) {
	next = 0;
	nextdata = s[0];
      } else{
	next = now + 1;
	nextdata = s[next];
      }

      sum1 = sum1- nextdata + data;
      if( sum1 > max) max = sum1;
      now = next;
      s[now] = data;
    }

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

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

// #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
// #define FORR(i, a, b) for (int i = (a); i > (b); --i)
// #define REP(i, n) for (int i = 0; i < (n); ++i)
// #define REPR(i, n) for (int i = n; i >= 0; i--)
// #define FOREACH(x, a) for (auto &(x) : (a))
// #define VECCIN(x)            \
// 	for (auto &youso_ : (x)) \
// 	cin >> youso_
// #define mp make_pair
// #define bitcnt __builtin_popcount
// #define All(a) (a).begin(), (a).end()
// template <typename T = long long>
// inline T IN()
// {
// 	T x;
// 	cin >> x;
// 	return (x);
// }
// inline void CIN() {}
// template <class Head, class... Tail>
// inline void CIN(Head &&head, Tail &&... tail)
// {
// 	cin >> head;
// 	CIN(move(tail)...);
// }
// #define CINT(...)    \
// 	int __VA_ARGS__; \
// 	CIN(__VA_ARGS__)
// #define LCIN(...)   \
// 	ll __VA_ARGS__; \
// 	CIN(__VA_ARGS__)
// #define SCIN(...)       \
// 	string __VA_ARGS__; \
// 	CIN(__VA_ARGS__)
// #define Yes(a) cout << (a ? "Yes" : "No") << "\n"
// #define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
// typedef vector<int> V;
// typedef vector<ll> VL;
// typedef pair<int, int> P;
// typedef pair<ll, ll> PL;
// typedef priority_queue<int> PQ;
// typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

vector<int> a;
int n, k;
vector<ll> ret;
int main()
{
	while (true)
	{
		cin >> n >> k;
		if (n == 0 && k == 0)
			break;
		a.resize(n);
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		int l, r;
		l = 0;
		r = 0;
		ll ans = 0, res = 0;
		while (l < n)
		{
			while (r - l < k && r < n)
			{
				ans += a[r++];
			}
			if (l == 0)
				res = ans;
			if (r - l == k)
				res = max(res, ans);
			ans -= a[l++];
		}
		ret.push_back(res);
	}
	for (int i = 0; i < ret.size(); i++)
	{
		cout << ret[i] << "\n";
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

#define MAX 100000
#define INF (10000*100000+1)
int main(){

	 std::ios_base::sync_with_stdio(false);

	int n,k,a[MAX];
	long long num,max;

	while(1){

		cin>>n>>k;
		if(n==0&&k==0) break;

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

		max=-1*INF;
		for(int i=0;i<=n-k;i++){
			num=0;
			for(int j=0;j<k;j++){
				num+=a[i+j];
			}
			max=(max<num)?num:max;
		}
		cout<<max<<endl;
		
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
#define debug(x) cout << #x << " = " << x << endl;
#define sq(x) ((x)*(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

int main(){
	int n, k;
	cin >> n >> k;
	queue<int> q;
	int sum = 0;
	int ans = -1e10;
	rep(i, n){
		int a;
		cin >> a;
		sum += a;
		q.push(a);
		if(q.size() >= k){
			ans = max(ans, sum);
			sum -= q.front();
			q.pop();
		}
	}
	cout << ans << endl;
}

C++: #include<stdio.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)

int n,k;
int aa[111111];

void getinput(){
	scanf("%d%d",&n,&k);
	rep(i,n)scanf("%d",&aa[i]);
}


int getfirstsum(int left,int right){
	if(left==right)return aa[left];
	return getfirstsum(left,(left+right)/2) +
			 getfirstsum((left+right)/2+1,right);
}

int main(void){
	
	getinput();
	
	int a = getfirstsum(0,k-1);
	int ans=a;
	rep(i,n-k){
		a = a-aa[i]+aa[i+k];
		if(ans<a){
			ans=a;
		}
	}
	
	printf("%d\n",ans);
}

C++: #include <iostream>
#include <algorithm>
#define N 100000
using namespace std;
int main(){
  int n,k,in[N],maxv,sum,i;
  while(1){
    cin >> n >> k;
    if(n==0&&k==0) break;
    maxv=-2000000;
    sum=0;
    for(i=0;i<n;i++){
      cin >> in[i];
      sum+=in[i];
      if(i>=k){
	sum-=in[i-k];
      }
      if(i>=k-1) maxv=max(maxv,sum);
    }
    cout << maxv << endl;
  }
  return 0;
}

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

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



int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    for(;;) {
        int n, k;
        std::cin >> n >> k;
        if (n == 0 && k == 0) break;
        std::vector<int> num(n);
        rep(i, n) std::cin >> num.at(i);

        int sum = std::accumulate(num.begin(),num.begin()+k,0);
        rep(i,n-k) sum = std::max(sum,sum-num.at(i)+num.at(k+i));

        std::cout << sum << "\n";
    }

    return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
	int *num,siz,time,max,nownum;
	while(cin>>time>>siz&&time!=0){
		num=new int[siz];
		for(int i=0;i<siz;++i){
			num[i]=0;
		}
		nownum=0;
		int dommy;
		max=pow((double)2,(double)sizeof(int)*8);
		for(int i=0;i<time;++i){
			cin>>dommy;
			nownum-=num[i%siz];
			nownum+=dommy;
			num[i%siz]=dommy;
			if(max<nownum){
				max=nownum;
			}
		}
		cout<<max<<endl;
		delete num;
	}
	return 0;
}

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

int main(){
	int n, k, num, max, ksum, i;
	while(true){
		cin>>n>>k;if(n==0&&k==0)break;
		queue<int> q;
		max=0;
		for(i=0;i<k;i++){
			cin>>num;
			q.push(num);
			max+=num;
			
		}
		ksum=max;
		for(i=k;i<n;i++){
			cin>>num;
			q.push(num);
			ksum -= q.front();
			q.pop();
			ksum += num;
			if(max<ksum) max = ksum;
		}
		cout<<max<<endl;
	}
	return 0;
}