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>
using namespace std;

int data[100010]={0};

int main(){
    int n,k;
    int sum = -1;
    int tmp,tmp2,tmp3,tmp4;
    while(1){
        cin >> n >> k;
        if(n == 0 && k == 0) break;
        for(int i=0;i<n;i++) cin >> data[i];
        for(int i=0;i<=(n-k)/4;i++){
            tmp = 0;
            tmp2 = 0;
            tmp3 = 0;
            tmp4 = 0;
            for(int j=i,g=n-(i+1),f=(n/2)+i,r=(n/2)+i;j<i+k;j++,g--,f++,r--){
                tmp += data[j];
                tmp2 += data[g];
                tmp3 += data[f];
                tmp4 += data[r];
            }
            if(sum < tmp) sum = tmp;
            else if(sum < tmp2) sum = tmp2;
            else if(sum < tmp3) sum = tmp3;
            else if(sum < tmp4) sum = tmp4;
        }
        cout << sum << endl;
    }
}

C++: //
//  main.cpp

#include <iostream>
using namespace std;

long long max(long long x,long long y){
	if(x > y){
		return x;
	}else{
		return y;
	}
}

int main(){
	while(1){
		int n,k;
		long long array[100001]={};
		long long total[100001]={};
		cin >> n >> k;
		if(n == 0 && k == 0)break;
		for(int i=0;i<n;i++){
			cin >> array[i];
		}
		long long x=0;
		for(int i=0;i<k;i++){
			x += array[i];
		}
		total[0] = x;
		for(int i=1;i<=n-k;i++){
			total[i] = total[i-1] - array[i-1] + array[i+k - 1];
		}
		long long answer = -10000000000;
		for(int i=0;i<100001;i++){
			answer = max(answer,total[i]);
		}
		cout << answer << endl;
	}
	
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

    while(1){
        int n, k;
        cin>> n>> k;
        if(n==0&&k==0) break;
        int a[n];
        for(int i=0; i<n; i++){
            scanf("%d", &a[i]);
        }

        long long s[n+1]={0};
        for(int i=0; i<n; i++){
            s[i+1]=s[i]+a[i];
        }
        long long ans=-100100100100100;
        for(int i=k; i<=n; i++){
            ans=max(ans, s[i]-s[i-k]);
        }

        cout<< ans<< endl;
    }

    return 0;
}

C++: #include <cstdio>

int main() {
    long n, k;
    for (;;) {
        long a[100002] = {};
        scanf("%ld %ld", &n, &k);
        if (n == 0)
            return 0;
        for (long i = 0; i < n; i++) {
            scanf(" %ld", &a[i]);
        }
        long max = 0;
        for (long i = 0; i < n - k + 1; i++) {
            long result = a[i] + a[i+1] + a[i+2];
            if (result > max)
                max = result;
        }
        printf("%ld\n", max);
    }
}

C++: #include<stdio.h>
int n[100000];
int main(){
	int a,b;
	while(1){
		scanf("%d%d",&a,&b);
		if(a==0&&b==0)return 0;
		int temp=0;
		for(int i=0;i<a;i++){
			int val=0;
			scanf("%d",&val);
			n[i]=(temp+=val);
		}
		int max=-1000000000;
		for(int i=0;i<a-b+1;i++){
			if(max<n[i+b]-n[i])max=n[i+b]-n[i];
		}
		printf("%d\n",max);
	}
}

C++: #include<iostream>

using namespace std;

int main(){
	
	int n,m;
	
	cin>>n>>m;
	
	int input[100000];
	
	for(int i=0;i<n;i++){
		cin>>input[i];
	}
	
	int cont = m;
	
	int now = 0;
	for(int i=0;i<m;i++){
		now += input[i];
	}
	
	
	int max = now;
	for(int i=m;i<n;i++){
		now-=input[i-m];
		now+=input[i];
		
		if(now>max){
			max=now;
		}
	}
	
	
	cout<<max<<endl;
	return 0;
}

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

int main()
{
	int n, k, i, j, inp, max=0;
	int *a;
	cin >> n >> k;
	a = new int[n];
	
	for (i = 0; i < n; i++){
		cin >> inp;
		a[i] = inp;
	}

	for (i = 0; i < n - k + 1; i++){
		int sum = 0;

		for (j = 0; j < k; j++){
			sum += a[i + j];
		}

		if (sum > max){ max = sum; }
	}

	cout << max << endl;

	delete[] a; 
	return 0;
}

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

int array[100001];
int n, k;

void add( int i, int x )
{
 	while( i <= n ){
		array[i] += x;
		i += i & (-i);
	}	
	
	return;
}

int sum( int i )
{
	int s = 0;
 	
	while( i > 0 ){
	 	s += array[i];
		i -= i & (-i);
	}
	
	return s;
}

int main()
{
	while( std::cin >> n >> k, n, k ){
		memset( array, 0, sizeof( array ) );
		
		for( int i = 1; i <= n; i++ ){
			int x;
			std::cin >> x;
			add( i, x );
		}
		
		int ans = -10001;
		for( int i = 1; i + k <= n; i++ ){
			ans = std::max( ans, sum( i + k ) - sum( i ) );
		}
		
		std::cout << ans << std::endl;
	}

 	return 0;	
}

C++: #include <stdio.h>
int main(void)
{
	for (;;)
	{
		int a,b,c,d,max=0;
		scanf("%d %d",&a,&b);
		int e[a];
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			scanf("%d",&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];
		}
		printf("%d\n",max);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int main(){
  int n, k;
  int N[100001], ans, sum;
  while(cin >> n >> k, n && k){
    memset(N, 10001, sizeof(N));
    ans = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> N[i];
    }
    for(int i = 0 ; i < n ; i++){
      sum = 0;
      for(int j = i ; j < k + i ; j++){
	sum += N[j];
	if(N[j+k-1] > 10000) break;
      }
      ans = max(ans, sum);
      //cout << ans << endl;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int n,k;
int a[100000];
int r,l;
int m,t;
int i,j;

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){
	while(1){
		scanf("%d %d",&n,&k);
		if(n==0&&k==0)return 0;
		for(i=0;i<n;i++)scanf("%d",&a[i]);
		r=0;l=k-1;
		m=0;
		for(i=0;i<k;i++){
			m+=a[i];
			t=m;
		}
		while(l<n-1){	
			t+=a[++l];
			t-=a[r++];
			m=max(m,t);
		}
		printf("%d\n",m);
	}
}