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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	while (1) {
		int a[100000];
		int n, k, sum = 0, ans = -999999;

		memset(a, 0, sizeof(a));
		cin >> n >> k;
		if (n == 0 && k == 0) break;

		REP(i, n) {
			cin >> a[i];
			sum += a[i];
			if (i >= k) sum -= a[i-k];
			ans = max(ans, sum);
		}

		cout << ans << 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[100003]={0};

    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[i]+=a[j];
      }
      }
      if(max<sum[i]){
	max=sum[i];
      }
      }
  
    printf("%d\n",max);

  }

  return 0;

}

C++: #include <cstdio>
int a[200000];
int main() {
    int n, k;
    while (scanf("%d %d",&n,&k)&&n!=0) {
        for (int i=0; i<n; i++) scanf("%d",&a[i]);
        int max=0;
        for (int i=0; i<k; i++) max+=a[i];
        int tmp=max;
        for (int i=0; i<n-k; i++) {
            tmp=tmp-a[i]+a[i+k];
            if (tmp>max) max=tmp;
        }
        printf("%d\n",max);
    }
    return 0;
}

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

using namespace std ;

int main()
{
	int n ;
	while( cin >> n ,n )
	{
		int m ;
		cin >> m ;
		int num[ 2 ] ;
		num[ 1 ] = 0 ;
		int ans = 0 ,cnt = 0 ;
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> num[ 0 ] ;
			if( i % m )
			{
				cnt += num[ 0 ] ;
			}
			else
			{
				cnt += num[ 0 ] - num[ 1 ] ;
				num[ 1 ] = num[ 0 ] ;
				ans = max( ans ,cnt ) ;
			}
		}
		cout << ans << endl ;
	}
	return 0 ;
}

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

int main(){
  int serchn,numn;
  int gh = 0;
  vector<int> outp;
  for(int a = 0;;a++){
    cin >> numn >> serchn;
    if(numn == 0 && serchn == 0)break;
    gh = 0;
    outp.resize(a+1,0);
    vector<int> num(numn);
    for(int n = 0;n<serchn - 1;n++){
      cin >> num[n];
      gh += num[n];
    }
    for(int n = 0;n<numn - serchn + 1;n++){
      cin >> num[n+2];
      gh += num[n+2];
      if(gh > outp[a])outp[a] = gh;
      gh += (-1) * num[n];
    }
  }
  for(int b = 0;b<outp.size();b++){
    cout << outp[b] << endl;
  }
  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++){
			for(int j=0;j<k;j++){
				sum[i]+=number[i+j];
			}
		}
		
		int ans;
		for(int i=0;i<n-k-1;i++){
			ans=max(sum[i],sum[i+1]);
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <array>
#include <set>
#include <string>
#include <numeric>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < n; i++)



int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    for(;;) {
        int n, k;
        std::cin >> n >> k;
        if (n == 0 && k == 0) break;
        std::vector<int> num(n);
        rep(i, n) std::cin >> num.at(i);

        int sum = std::accumulate(num.begin(),num.begin()+k,0);
        rep(i,n-k) sum = std::max(sum,sum-num.at(i)+num.at(k+i));

        std::cout << sum << "\n";
    }

    return 0;
}

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

long long int num[100100];

int main(){
    long long int n,m;
    long long int sum=0;
    long long int ans=0;
    while(1){
        cin>>n>>m;
        if(n==0&&m==0)break;
        for(int i=0;i<100100;i++){
            num[i]=0;
           // if(num[i+1]==0)break;
        }
        for(int i=0;i<n;i++){
            cin>>num[i];
            if(i<m)sum+=num[i];
        }
        for(int i=1;i<n;i++){
            sum=sum-num[i-1]+num[i];
            if(ans<sum)ans=sum;
        }
        cout<<ans<<endl;
        ans=0;
        sum=0;
        }
    return 0;
}

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++){
			cin>>inp[i];
		}
		Int max=-2000000000;
		for(i=0;i<=n-m;i++){
			Int sum=0;
			int k;
			for(k=0;k<m;k++){
				sum+=inp[i+k];
				//cout<<sum<<endl;
			}
			if(max<sum)max=sum;
		}
		cout<<max;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int a[100010];
long long ans,maxx;
int main()
{
	int i,n,m;
	while(cin>>n>>m&&n!=0&&m!=0)
	{
		ans=-9999999,maxx=0;
		for(i=1;i<=n;i++)
		{
			cin>>a[i];
			if(i<m)maxx+=a[i];
			else if(i>=m)
			{ 
			    maxx+=a[i];
			    if(maxx>ans)ans=maxx;
			    maxx-=a[i-m+1];
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <cstdio>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;


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

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