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 <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const int INF = 999999999;

vector<int> ret;

void solve(vector<int>& a, int k) {
    int n = a.size();
    vector<int> cs(n+1, 0);
    for(int i = 1; i < n+1; i++) {
        cs[i] = cs[i-1];
        cs[i] += a[i-1];
    }

    int ans = (-1) * INF;
    for(int i = 0; i < n+1; i++) {
        int now = cs[i+k] - cs[i];
        ans = max(ans, now);
    }
    ret.push_back(ans);
}

int main() {
    do {
        int n, k;
        cin >> n >> k;
        if (n == 0 && k == 0) break;
        vector<int> a(n, 0);
        for(int i = 0; i < n; i++) cin >> a[i];
        solve(a, k);
    } while(true);

    for(auto &r : ret) {
        cout << r << endl;
    }
}

C++: #include <stdio.h>
int RB[100005],ans;
int main() {int N,K,i,j=0;while (1) {scanf("%d %d",&N,&K);if (!N) return 0;for (i=0,K--;i<K;i++) scanf("%d",&RB[i]),j+=RB[i];ans=j;for (i=K;i<N;i++) scanf("%d",&RB[i]),j+=RB[i],(ans=(ans>j)?ans:j),j-=RB[i-K]; printf("%d\n",ans);}}

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

int main()
{
  int n,k;
  cin >> n >> k;
while(n!=0||k!=0){
  int l, i=0, a[100000], S[100000];
  S[0] = 0;
  while(cin >> l){
    a[i] = l;
    if (i>=1)S[i] = S[i-1]+a[i-1];
    i++;
  }
  int q = i; i = 0;int m = a[0];
  while(k+i<=q){
    if (m > S[i+k-1]-S[i])
    m = S[i+k-1]-S[i];
    i++;
  }
  cout << m << endl;
}
cin >> n >> k;
}

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

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int inp[1000000];
	
int main() {
	int n,m;
	while(n=in(),m=in()){
		int i;
		for(i=0;i<n;i++){
			inp[i]=in();
		}
		Int max;
		Int sum=0;
		int k;
		for(k=0;k<m;k++){
			sum+=inp[k];
		}
		max=sum;
		for(i=0;i<=n-m;i++){
			if(max<sum)max=sum;
			sum-=inp[i];
			if(i!=n-m)sum+=inp[i+m];
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

ll n, k, a[100000];

int main() {
  while (1) {
    scanf("%lld%lld", &n, &k);
    if (n == 0) break;
    for (ll i = 0; i < n; i++) scanf("%lld", &a[i]);
    ll sum = 0;
    for (ll i = 0; i < k; i++) sum += a[i];
    ll ans = sum;
    for (ll i = k; i < n; i++) {
      sum += a[i];
      sum -= a[i - k];
      ans = max(ans, sum);
    }
    printf("%lld\n", ans);
  }
}

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

using namespace std;

int n, k ,i = 0;
long long int a[100000];
long long int result[100][2];

int main()
{
	for (;; i++)
	{
		cin >> n >> k;
		if (n == 0)
		{
			break;
		}

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

		for (int p = 0; p < n - k; p++)
		{
			for (int q = 0; q < k; q++)
			{
				result[i][0] += a[p + q];
			}
			result[i][1] = max(result[i][0], result[i][1]);
			result[i][0] = 0;
		}
	}
	for (int p = 0; p < i; p++)
	{
		cout << result[i][1] << endl;
	}

	getchar();
	getchar();

	return 0;
}

C++: const int MAX_N = 1 << 17, INF = 1 << 24;
class BIT{
public:
	BIT(int _n)
		:n(_n){
		std::fill(bit, bit+n, 0);
	}
	int sum(int i){
		int s = 0;
		while(i > 0){
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	int add(int i, int x){
		while(i <= n){
			bit[i] += x;
			i += i & -i;
		}
	}
private:
	int bit[MAX_N], n;
};

int main(){
	int n, k;
	while(std::cin >> n >> k, n){
		BIT b(n+1);
		for(int i=1;i<=n;i++){
			int a_i;
			std::cin >> a_i;
			b.add(i, a_i);
		}

		int res = -INF;
		for(int i=1;i+k-1<=n;i++){
			res = std::max(res, b.sum(i+k-1) - b.sum(i-1));
		}

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

C++: #include <iostream>
#include <algorithm>
constexpr int MAX_N=100000;

int n,k;
int a[MAX_N];
long long int sum=0;
long long int res=0;

int main(){
    while(1){
        std::cin>>n>>k;
        if(n+k==0)
            break;
        res=0;
        sum=0;

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

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

        res=sum;

        int s=0,t=k;

        while(t<=n){
            sum-=a[s];
            sum+=a[t];
            ++s;
            ++t;
            res=std::max(res,sum);
        }
        std::cout<<res<<std::endl;
    }
    return 0;
}

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

int main(){
  int n,k;
  int a[1000000];

  for(;;){
    cin >> n >> k;
    if(!n && !k)break;

    for(int i=0;i<n;i++)cin >> a[i];
    int sum = 0;
    for(int i=0;i<k;i++)sum += a[i];
    int m = sum;
    for(int i=k;i<n;i++){
      sum += a[i] - a[i-k];
      m = max(m,sum);
    }
    cout << m << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int k,n,a[100]={0};
    double cube=0,ans=0;
    while(1){
       cin >> n >> k;
       if(n==0&&k==0)break;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n-k;i++){
       cube=0;
       for(int j=0;j<k;j++){
        cube +=a[i+j];
       }
       if(cube>ans)ans=cube;
    }
    cout << ans << endl;
    }
return 0;
}

C++: #include<iostream>
main(){for(int n,k,a[100000],s,M,i,j;std::cin>>n>>k,n;printf("%d\n",s)){for(i=M=0;i<n;i++)std::cin>>a[i];for(i=n;i-->k;M<s&(M=s))for(j=s=0;j<k;j++)s+=a[i-j];}}

C++: #include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
ll n,k;
ll a[200000];

bool input(){
    scanf("%lld%lld",&n,&k);
    if(n == 0 && k == 0)
        return false;
    REP(i,n)
        scanf("%lld",a + i);
    return true;
}
void solve(){
    ll sum = 0;
    REP(i,k){
        sum += a[i];
    }
    ll maxi = sum;
    REP(i,n - k){
        sum = sum - a[i] + a[i + k];
        maxi = max(maxi,sum);
    }
    printf("%lld\n",maxi);
}
int main(){
    while(input())
    solve();
}

C++: #include <stdio.h>
int main(){
	for(;;){
		int max=0,set[100000],n,m,a,b,c;
		scanf("%d%d",&n,&m);
		if(n==0&&m==0){
			break;
		}
		for(a=0;a<n;a++){
			scanf("%d",&set[a]);
		}
		for(a=0;a<n-m;a++){
			c=0;
			for(b=0;b<m;b++){
				c+=set[a+b];
			}
			if(max<c)max=c;
		}
		printf("%d\n",max);
	}
	return 0;
}