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

int main() {
    int N, M;
    while (cin >> N >> M, N || M) {
        vector<long long int> v(N);
        for (int i = 0; i < N; i++) {
            cin >> v[i];
            if (i > 0) v[i] += v[i-1];
        }

        long long int ans = -10000000000;
        for (int i = 0; i < N - M; i++) {
            ans = max(ans, v[i+M] - v[i]);
        }

        cout << ans << endl;
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
	while (1) {
		int n, k, a[100005] = { 0 }, sum[100005] = { 0 }, m = -99999999;
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
		for (int i = 0; i < n; i++) cin >> a[i];
		for (int i = 0; i < k; i++) {
			sum[0] += a[i];
		}
		for (int i = 1; i < n - 2; i++) {
			sum[i] = sum[i - 1] + a[i + 2] - a[i - 1];
		}
		for (int i = 0; i < n - 2; i++) {
			if (m < sum[i]) {
				m = sum[i];
			}
		}
		cout << m << endl;
	}
}

C++: 

#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}



template< class T >
struct CumulativeSum {
  vector< T > data;

  CumulativeSum(int sz) : data(sz, 0) {};

  CumulativeSum(vector< T> v) : data(v.size()+1,0) {rep(i,v.size()) add(i+1,v[i]); build();};

  void add(int k, T x) {
    data[k] += x;
  }

  void build() {
    for(int i = 1; i < data.size(); i++) {
      data[i] += data[i - 1];
    }
  }

  T query(int l,int r) {  // [l,r)
    if(l < 0) return (0);
    return (data[min(r,(int)data.size()-1)]-data[min(l,(int)data.size()-1)]);
  }
};


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,k;
  while(true){
    cin>>n>>k;
    if(n==0) break;
    vi a(n);
    rep(i,n){
      cin>>a[i];
    }
    CumulativeSum<int> v(a);
    int ans=-INF;
    rep(i,n-k){
      ans=max(ans,v.query(i,i+k));
    }
    cout<<ans<<endl;
  }


}

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

using namespace std;

int suretu[100000];
int cont = 0;
int max_sum = 0;

int ret_maxsum(int n, int k, int wa, bool isBegin)
{
	/*
	int temp = 0;
	int max = 0, cont = 0;
	int wa;							//ツ陳シツ前ツづ個禿アツづつづ個計ツ算ツづ系ツ古つづ個計ツ算ツづ個和
	
	for(int i = 0; i < n-k+1; i++){
		for(int j = 0; j < k; j++){
			temp += suretu[cont+j];
			if(
			printf("suretu%d = %d\n",j,suretu[cont+j]);
		}
		cout << "**" << endl;
		if(temp > max){
			printf("*maxツ更ツ新\n");
			max = temp;
		}
		temp = 0;
		cont++;
	}
	
	return max;
	*/
	
	int temp = 0;
	int i;
	
	if(isBegin == 1){
		for(i = 0; i < k; i++){
			temp += suretu[cont+i];
		}
	}
	else{
		temp += wa + suretu[cont+k-1];
	}
	wa = temp - suretu[cont];
//	printf("temp = %d\nwa = %d\n\n",temp,wa);
	cont++;
	
	if(max_sum < temp){
//		cout << "maxツ更ツ新:" << temp << endl;
		max_sum = temp;
	}
	
	if(cont == n-k+1){
		return max_sum;
	}
	else{
		return ret_maxsum(n, k, wa, 0);
	}
}
	

int 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, 1));
	}
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  int N;
  cin >> N;
  //いもす！！
  vector<int> P(1000, 0);

  for(int i = 0; i < N; i++) {
    int s, e;
    cin >> s >> e;
    P[s]++;
    P[e]--;
  }
  //るいせきわ(=いたにんずう) 1ひいてつかう
  vector<int> S(1001);
  S[0] = 0;
  for(int i = 0; i < N; i++) {
    S[i + 1] = S[i] + P[i];
  }
  bool flag = true;
  for(int i = a; i <= b; i++) {
    if(S[i] > 0) { flag = false; }
  }

  if(flag)
    cout << 0 << endl;
  else
    cout << 1 << endl;

  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int n, k;
int a[100000];
int s;
int main()
{
	cin >> n >> k;
	while(n*k!=0)
	{
		s=0;
		for(int i=0; i<k; i++)
		{
			cin >> a[i];
			s+=a[i];
		}
		for(int i=k; i<n; i++)
		{
			cin >> a[i];
			s=max(s, s+a[i]-a[i-k]);
		}
		cout << s << endl;
		cin >> n >> k;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int n, k;
    while(cin>>n>>k, n){
        vector<ll> a(n+10, 0);
        for(int i=1; i<=n; i++){
            cin>>a[i];
            a[i]+=a[i-1];
        }

        ll ans=-INF;
        for(int i=1; i+k-1<=n; i++){
            chmax(ans, a[i+k-1]-a[i-1]);
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,k,sum,max,a,i;
	int *data;
	while(cin>>n>>k){
		if(n==0 && k==0){break;}
		data=new int[n];
		sum=0;
		for(i=0;i<k;i++){
			cin>>data[i];
			sum+=data[i];
		}
		max=0;
		for(i=k;i<n;i++){
			cin>>data[i];
			sum-=data[i-k];
			sum+=data[i];
			if(sum>max){
				max=sum;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(){
int n,m,cont,now,max,i,input[100000];
while(1){
scanf("%d%d",&n,&m);
if(n==0 && m ==0)
break;
for(i=0;i<n;i++)
scanf("%d",&input[i]);
now = 0;
for(i=0;i<m;i++)
now += input[i];
max=now;
cont = m;
for(i=m;i<n;i++){
now-=input[i-m];
now+=input[i];
if(now>max)
max=now;
}
printf("%d\n",max);
}
}