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

using namespace std;

int main() {
    while(true) {
        int n, k;
        cin >> n >> k;
        if(!n && !k) break;

        int sum = 0;
        int ans = 0;
        queue<int> q;
        for(int i = 0; i < n; ++i) {
            int num;
            scanf("%d", &num);

            sum += num;
            if(i == k-1) ans = sum;
            if(i >= k) {
                sum -= q.front();
                q.pop();
                ans = max(ans, sum);
            }
            q.push(num);
        }

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

C++: #include<iostream>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    while(n!=0||k!=0){
       vector<int> a(n);
        cin >> a;
        S[0]=0;
        for(int i=1;i==n;i++){
            S[i]=S[i-1]+a.at(i-1);
        }
        int x=S[k];
        for(int l=1;l==n-k;l++){
            if(x<S[k+l]-S[l]){
                x==S[k+l]-S[l];
            }
             cout << x << endl;
            cin >> n >> k;
        }

    }

}

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

int main() {
  while (true) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0) break;
    vector<int> v(n);
    for (auto&& w : v) cin >> w;
    vector<int> s(n + 1, 0);
    for (int i = 0; i < n; i++) {
      s[i + 1] = s[i] + v[i];
    }
    int ret = 0;
    for (int i = 0; i + k < n + 1; i++) {
      int sm = s[i + k] - s[i];
      ret = max(ret, sm);
    }
    cout << ret << endl;
  }
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(){
  
  long long n,k,max=0,ans,i;
  cin >> n >> k;
  long long a[n];
  
  for(i = 0;i < n;i++){
    scanf("%lld",&a[i]);
    
    if(i < k){
      max += a[i];
      ans = max;
    }
    else {
      max = max + (a[i] - a[i-k]);
      if(ans < max) ans = max;
    }
  }

  printf("%lld\n",ans);
  return (0);
}

C++: #include <bits/stdc++.h>

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	vector<int> ans;

	while(true){
		int n, k;
		cin >> n >> k;

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

		vector<int> input;
		rep(i, n){
			int a;
			cin >> a;
			input.push_back(a);
		}

		vector<int> cumu;
		cumu.push_back(0);

		rep(i, n){
			cumu.push_back(cumu[i] + input[i]);
		}

		int sumMax = 0;
		rep(i, n){
			if(n < i + k) break;

			if(sumMax < cumu[i + k] - cumu[i]) sumMax = cumu[i + k] - cumu[i];
		}

		ans.push_back(sumMax);
	}

	rep(i, ans.size()){
		cout << ans[i] << endl;
	}

	return 0;
}

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;
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>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  bool m = false;
  c = getchar();
  while(!isdigit(c)){
    if(c == '-') m = true;
    c = getchar();
  }
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  if(m) ret = -ret;
  return ret;
}

int main(){
  int n,k;
  while((n = getInt()) + (k = getInt())){
    vector<int> tmp(k);
    int kk = 0;
    int nn = 0;
    int sum = 0;
    int ans = INT_MIN;
    REP(i,n){
      int tt = getInt();
      //cout << "tt=" << tt << endl;
      if(i >= k){
        sum -= tmp[nn++];
        nn %= k;
      }
      tmp[kk++] = tt;
      kk %= k;
      sum += tt;
      if(i >= k - 1){
        ans = max(ans, sum);
      }
    }
    print(ans);
  }
  return 0;
}

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

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 1000000009;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int t, d; };

int main()
{
	int n, k;
	while (cin >> n && n)
	{
		cin >> k;
		vector<LL> sums(n);
		rep(i, n)
		{
			cin >> sums[i];
			if (i != 0)
				sums[i] += sums[i - 1];
		}
		LL ans = sums[k];
		for (int i = 0; i + k < n; i++)
		{
			ans = max(ans, sums[i + k - 1] - sums[i - 1]);
		}
		cout << ans << endl;
	}
	return 0;
}