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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

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

int main(void){
  int n,k;
  int a[100001];
  while(cin>>n>>k){
    if(n==0) break;
    REP(i,n)cin>>a[i];
    int sum = 0;
    int mx;
    REP(i,k){
      sum+=a[i];
    }
    mx = sum;
    for(int i=k;i<n;i++){
      sum-=a[i-k];
      sum+=a[i];
      mx = max(sum,mx);
    }
    cout<<mx<<endl;
  }
  return 0;
}

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

using namespace std;

int main(void) {
	int n, k, in, tmp, res;
	vector<int> sum;
	int i, j;

	while(true) {
		cin >> n >> k;
		if((n == 0 && k == 0) || cin.eof()) { break; }
		sum.clear();
		res = 0;
		for(i = 0; i < k; i++) {
			cin >> in;
			sum.push_back(in);
			res += sum[i];
		}
		for(i = k; i < n; i++) {
			cin >> in;
			tmp = 0;
			for(j = 1; j < k; j++) {
				sum[j-1] = sum[j];
				tmp += sum[j-1];
			}
			sum[k-1] = in;
			tmp += sum[k-1];
			res = max(res, tmp);
		}
		cout << res << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
  int n, m, a[100000], t, s;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0){
      break;
    }
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }

    t = s = 0;
    for(int i = 0; i < m; i++){
      t += a[i];
    }
    s = t;
    for(int i = m; i < n; i++){
      t += (a[i] - a[i-m]);
      if(s < t){
	s = t;
      }
    }
    cout << s << endl;
  }

  return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	while(1){
	int k,n,s=0,cn=0;
	cin>>k>>n;
	if(k==0 && n==0){
		break;
	}
	int dat[1000];
	for(int i=0;i<k;i++){
		cin>>S>>dat[i];
	}
	for(int j=0;j<k-n+1;j++){
		cn=0;
		for(int k=0;k<n;k++){
			cn+=dat[j+k];
		}
		s=max(s,cn);
	}
	cout<<s<<endl;
	}
	return 0;
}

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

using namespace std;

int b[100000] = {};

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

C++: #include <iostream>
using namespace std;
int main()
{
  int n,k;
  for(;cin>>n>>k,n;)
    {
      int d[n];
      for(int i=0;i<n;i++)
	cin>>d[i];
      int max=-10000;
      for(int i=0;i<n-k;i++)
	{
	  int sum=0;
	  for(int j=i;j<i+k;j++)
	    {
	      sum+=d[j];
	    }
	  if(max<sum)
	    max=sum;
	}
      cout<<max<<endl;
    }
}

C++: #include<iostream>
using namespace std;
int n=0, k=0;
double a[100001] = {}, b[100001] = {}, ans=0;
int main(){
while (cin>>n>>k){
n=0; k=0;
a[100001] = {}; b[100001] = {}; 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[1 + x];
}
ans=b[1];
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];
}
}
cout << ans << endl;
}
return 0;
}

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

int main() {
	int n,m;
	while(cin>>n>>m,n,m){
		int ans=0;
		queue<int> que;
		for(int i=0,num;i<m;i++){
			cin>>num;
			que.push(num);
			ans+=num;
		}
		for(int i=m,num,sum=ans-que.front();i<n;i++){
			que.pop();
			cin>>num;
			ans=max(ans,sum+=num);
			sum-=que.front();
			que.push(num);
		}
		cout<<ans<<endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define INF ( 1 << 30 )
int main(){
  int a[100000] , n, k;
  while(cin >> n >> k , n){
    int sum = 0 , ans = -INF;
    for(int i = 0 ; i < n ; i++ ) cin >> a[i];
    for(int i = 0 ; i < k - 1 ; i++ ) sum += a[i];
    for(int i = k - 1 ; i < n ; i++ ){
      sum += a[i];
      ans = max(sum,ans);
      sum -= a[i-k+1];
    }
    cout << ans << endl;
  }
}

C++: #include<iostream>
using namespace std;
int main(){
    int a[100010],n,k;
    while(cin>>n>>k,n||k){
        for(int i=0;i<n;i++)cin>>a[i];
        int mx=-1;
        for(int i=0;i<=n-k;i++){
            int sum=0;
            for(int j=i;j<i+k;j++)sum+=a[j];
            mx=max(mx,sum);
        }
        cout<<mx<<endl;
    }
}

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

int main(){
  int numn,lisn,num;
  vector<int> outp;
  int outn = 1;
  for(int l = 0;;l++){
    cin >> numn >> lisn;
    if(numn == 0 && lisn == 0)break;
    outp.resize(l+1,0);
    vector<int> lists(numn,0);
    for(int n = 0;n<numn;n++){
      cin >> num;
      lists[n] = num;
    }
    for(int k = 0;k<numn-2;k++){
      outn = lists[k] + lists[k + 1] + lists[k + 2];
      if(outp[l] < outn){
        outp[l] = outn;
      }
    }
  }
  for(int q = 0;q<outp.size();q++){
    cout << outp[q] << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(void){
    for(;;){
	int n,k;
	int sum=0,ans=0;
	int a[100010]={0};
	cin >> n;
	cin >> k;
	if(n==0&&k==0)break;
	for(int i=0;i<n;i++){
	    cin >> a[i];
        }
    for(int i=0;i<k;i++){
        sum+=a[i];
        }
    ans=sum;
    for(int i=k;i<n;i++){
        sum+=a[i];
        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 a[100000][5]={0};
int b[100000];
int Y(int l,int j,int m){
long long s=0;
int u;
if(m-j>=l){
for(u=j;u<j+l&&u<m;u++){
s+=b[u];
}
}
return s;
}
int main(){
while(1){
int n,k,i,p=0,o=0;
cin>>n>>k;
if(n==0&&k==0)break;
for(i=0;i<n;i++){cin>>b[i];}
a[0][p]=Y(k,o,n);
for(i=1;i<n;i++){
a[i][p]=max(a[i-1][p],Y(k,i,n));
}
cout<<a[n-1][p]<<endl;
p++;
}
return 0;
}