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 <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int a[MAX_N];

int main()
{
	int n,k;
	while(1){
		scanf("%d%d",&n,&k);
		if(n==0){
			break;
		}
		rep(i,n){
			scanf("%d",&a[i]);
		}
		ll ans=0;
		ll s=0;
		int id=0;
		while(id<n){
			s += a[id];
			if(id>=k){
				s-=a[id-k];
				ans = max(ans,s);
			}else if(id==k-1){
				ans = s;
			}
			id++;
		}
		cout << ans << "\n";
	}
	return 0;
}

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

/* {{{ */
#define CL(N) cout << N << endl
#define DCT(N) cout << "debug " << N << endl
#define REP(i, N) for (int i = 0; i < N; i++)
/* }}} */

int main()
{
	int n, l;

    while (cin >> n >> l, n || l){
        int a[100000];
        REP(i, n){
            cin >> a[i];
        }

        int sum = 0;
        REP(i, n - (n - l)){
            sum = max(sum, a[i] + a[i + 1] + a[i + 2]);
        }

        CL(sum);
    }

	return (0);
}

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

using ll = long long;

constexpr int MAX_N = 100000;

int N, K;
ll csum_A[MAX_N];

int main(){

	while(true){

		std::cin >> N >> K;

		if(N == 0 && K == 0) break;

		for(int i = 0; i < N; ++i){

			ll input;

			std::cin >> input;

			if(i == 0) csum_A[i] = input;
			else csum_A[i] = csum_A[i - 1] + input;
		}

		ll ans = csum_A[K - 1];

		for(int i = 0; i < N - K; ++i){

			ans = std::max(ans, csum_A[i + K] - csum_A[i]);

		}

		std::cout << ans << std::endl;
	}

	return 0;
}

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

int main(){

  int n,k,i,j;

  while(1){

  int a[100003]={0};
  int max=0,sum;

    scanf("%d %d",&n,&k);

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

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

    for(i=0;i<n;i++){
      if(i+k<=n){
      for(j=i;j<i+k;j++){
	sum+=a[j];
      }
      }
      if(max<sum){
	max=sum;
	sum=0;
      }
      }
  
    printf("%d\n",max);

  }

  return 0;

}

C++: #include<iostream>
using namespace std;
int main(){
	while (true){
		int n, k;
		double a[100001] = {}, b[100001] = {}, ans;
		cin >> n >> k;
		if (n == 0 || k == 0)	break;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
		}
		for (int x = 0; x<k; x++){
			b[1] += a[1 + x];
		}
		for (int i = 2; i <= n; i++){
			if (a[i + k - 1] == 0)	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			if (b[i]>b[i - 1]){
				ans = b[i];
			}
		}
		if (ans == 0){
			cout << b[1] << endl;
		}
		else{
			cout << ans << endl;
		}
	}
	return 0;
}

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

C++: #include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <list>
#include <functional>
#include <algorithm>
#include <array>

using namespace std;

int main(int, char**){
    int n,k;
    while(1){
	cin >> n >> k;
	if(n==0&&k==0) break;
	vector<int> as(n);
	for(int i(0);i<n;++i) cin >> as[i];
	int sum=0;
	for(int i(0);i<k;++i) sum += as[i];
	for(int i(k);i<n;++i){
	    int tmp = sum + as[i] - as[i-k];
	    if(tmp>sum) sum = tmp;
	}
	cout << sum << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long m[100000][2];
int main(){
while(1){
long long n,k,i,j,x=0;
cin>>n>>k;
if(n==0&&k==0)break;
for(i=0;i<n;i++)cin>>m[i][0];
m[0][1]=m[0][0];
for(i=1;i<n;i++){
m[i][1]=m[i-1][1]+m[i][0];
}
x=m[k-1][1];
for(i=k;i<n;i++){
x=max(x,m[i][1]-m[i-k][1]);
}
cout<<x<<endl;
return 0;
}
}

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

using namespace std;

void solve()
{
	int n, k;
	while(cin >> n >> k, n || k)
	{
		int max = 0;
		int sum = 0;
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		for(int i = 0; i < k; ++i)
		{
			sum += Vec[i];
		}
		if(max < sum)
		{
			max = sum;
		}
		for(int i = 1; i + k - 1 < n; ++i)
		{
			sum -= Vec[i - 1];
			sum += Vec[i + k - 1];
			if(max < sum)
			{
				max = sum;
			}	
		}
		cout << max << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
using namespace std;
int suretu[100000];
int cont = 0, max_sum = 0;

int ret_maxsum(int n, int k, int wa )
{
	int temp = 0;
	int i;
	/*
	if(isBegin == 1){
		for(i = 0; i < k; i++){
			temp += suretu[cont+i];
		}
	}
	*/
	temp += wa + suretu[cont+k-1];
	wa = temp - suretu[cont];
	cont++;
	if(max_sum < temp){max_sum = temp;}
	if(cont == n-k+1){return max_sum;}
	else{return ret_maxsum(n, k, wa);}
}
main()
{
	for(;;){
		int n,k;
		cin >> n;
		cin >> k;
		if(n == 0 && k == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> suretu[i];
		}
		printf("%d\n",ret_maxsum(n, k, 0));
	}
}

C++: #include <stdio.h>
int array[5000],n,k,max;

void func(int now){
	int i,j,temp=0;
	
	if(now==n-k)return;
	
	for(i=now;i<now+k;i++){
		temp+=array[i];
	}
	if(temp>max)max=temp;
	func(now+1);
}
		
		


int main(void){
	int i;
	
	while(scanf("%d",&n),n){
		max=0;
		
		scanf("%d",&k);
		for(i=0;i<n;i++){
			scanf("%d",&array[i]);
		}
		func(0);
		
		printf("%d\n",max);
		
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

#define MAX 100000

int main(){

	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];
		}

		num=0;
		for(int j=0;j<k;j++){
			num+=a[j];
		}
		max=num;

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

	return 0;
}

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

int main(){
	int n, k, x, maxnum = 0;
	cin >> n >> k;
	int wa[100000];
	for(int i=0;i<100000;i++) wa[i] = 0;
	for(int i=0;i<n;i++){
		cin >> x;
		for(int j=0;j<k;j++){
			wa[i+j] += x;
		}
	}
	cin >> x >> x;
	for(int i=k-1;i<n;i++){
		if(maxnum < wa[i]) maxnum = wa[i];
	}
	cout << maxnum;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int n,k;
    while (cin >> n >> k, n) {
        vector<ll> a(n);
        REP(i,n) cin >> a[i];
        vector<ll> sum(n+1,0);
        REP(i,n) {
            sum[i+1] = sum[i] + a[i];
        }
        ll ans = 0;
        for (int i=k; i<n+1; i++) {
            ans = max(ans, sum[i] - sum[i-k]);
        }
        cout << ans << endl;
    }
    return 0;
}