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

using namespace std;

int main(){
  int a,b;
  long int ant,kazu[100000],maxt;
  while(1){
    maxt=0;
    scanf("%d%d",&a,&b);
    if(a==0&&b==0) return 0;
    for(int i=0;i<a;i++)scanf("%ld",&kazu[i]);
    for(int i=0;i<b;i++) maxt=maxt+kazu[i];
    ant=maxt;
    for(int i=0;i<a-b;i++) {maxt=max(maxt,ant-kazu[i]+kazu[i+b]); 
      ant=ant-kazu[i]+kazu[i+b];
    }
    printf("%ld\n",max(maxt,ant));
  }
  
}

C++: /* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

// #define int long long

/* cpp template {{{ */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
using namespace std;

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  for (int n, k; cin >> n >> k, n || k; ){
    vi sum(n + 1, 0);
    cin >> sum[1];
    REPS(i, 2, n + 1) cin >> sum[i], sum[i] += sum[i - 1];

    int ans = -INF;
    for (int i = k; i <= n; i++){
      ans = max(ans, sum[i] - sum[i - k]);
    }
    print(ans);
  }

  return (0);
}

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

int main(){
  int n,k,p,ans=0,sum=0;
  cin>>n>>k;

  while(n!=0&&k!=0){
    vector<int> v;
    for(int i=0;i<n;i++){
      cin>>p;
      v.push_back(p);
    }
    for(int i=0;i<=n-k;i++){
      for(int j=0;j<k;j++){
        sum+=v[i+j];
      }
      if(sum>=ans){
        ans=sum;
      }
      sum=0;
    }
    cin>>n>>k;
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,result = -100000;
    int num[100005] = {0};
    int memo[100000] = {0};
    while(cin >> n >> m,n + m)
    {
        for(int i = 0; i < n; i++)cin >> num[i];
        for(int i = m-1; i < n; i++)
        {
            memo[i]=0;
            if(i == m-1)
            {
                for(int j = 0; j < m; j++)
                {
                    memo[i] += num[i-j];
                }
            }
            else if(i > m-1)
            {
                memo[i] = memo[i-1] +  num[i] - num[i-m];
            }
        }
        for(int i = m - 1; i < n; i++)
        {
            result = max(result,memo[i]);
        }
        cout << result << endl;
        result = -100005;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int n,k,a,max;
  int set[100001];
  while(1){
    scanf("%d %d",&n,&k);
  if(n==0 && k==0)break;
  max=0;
  for(int i=0;i<n;i++){
    scanf("%d",&set[i]);
  }
  for(int i=0,sum=0;i<n-k+1;i++,sum=0){
    if(set[i-1]<set[i+k-1] || i==0){
      for(int j=i,l=i+k-1;;j++,l--){
	sum += set[j]+set[l];
	if(l-j==1){
	  break;
	}else if(l==j){
	  sum-=set[j];
	  break;
	}
      }
    }
    if(max<sum || i==1){
      max=sum;
    }
  }
  printf("%d\n",max);
  }
}

C++: #include <iostream>
#include <algorithm>
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 <stdio.h>
#include <string.h>

#define MAX_BIT_SIZE 100001

int BIT[MAX_BIT_SIZE];
int n;
int save[MAX_BIT_SIZE];

int sum(int index) {
    int ret = 0;
    index += 1;

    while (index > 0) {
        ret += BIT[index];
        index -= (index & (-index));
    }

    return ret;
}

void add(int index, int value) {
    int i = 1;
    index += 1;

    while (index <= n) {
        BIT[index] += value;
        index += (index & (-index));
    }
}

int main() {
    while (1) {
        int k;
        int i;
        int max_count = 0;

        scanf("%d %d", &n, &k);
        if (n == 0 && k == 0) return 0;

        memset(BIT, 0, MAX_BIT_SIZE);

        for (i=0;i<n;i++) {
            int d;
            scanf("%d", &d);
            save[i] = d;
            add(i, d);
        }

        for (i=0;i<n-k;i++) {
            int now_count = sum(i+k) - sum(i);
            if (now_count > max_count){
                max_count = now_count;
            }
        }

        printf("%d\n", max_count);
    }
}

C++: #include <iostream>
#include <algorithm>
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<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int N,M;
        int lis[100002];
        cin>>N>>M;
        if(N==0&&M==0)break;
        for(int i=0;i<N;i++)cin>>lis[i];
        int now=0,ans=0;
        for(int i=0;i<M;i++)now+=lis[i],ans+=lis[i];
        for(int i=1;i+M<=N;i++)now=now-lis[i-1]+lis[i+M-1],ans=max(now,ans);
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

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