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;
const int SIZE=100001;
int a[SIZE]={00},b[SIZE]={00},c[SIZE]={00};

int main() {
	while(true){
		int n=0,k=0;
		cin >> n >> k;
		if(n==0) break;
		int max;
		for(int i=1;i<=n;i++){
			cin >> a[i];
		}
		for(int i=1;i<=n;i++){
			b[i]=b[i-1]+a[i];
		}
		for(int i=0;i<=n-k;i++){
			c[i]=b[i+k]-b[i];
		}
		max=c[1];
		for(int i=0;i<n;i++){
			if(max<c[i]){
				max=c[i];
			}
		}
		cout << max << endl;
	}
	return 0;
}

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

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

int main()
{
  int n, k;
  cin >> n >> k;

  int a[101010] = {0};

  cin >> a[1];
  for (int i = 2; i < n + 1; i++){
    cin >> a[i];
      a[i] += a[i - 1];
  }

  int max_n = -1e9;
  for (int i = 0; i < n - k; i++){
    max_n = max(max_n, a[k + i] - a[i]);
  }

  cout << max_n << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,k,box[10000]={0},ans=0,sum=0,summ;
int main(){
    cin >> n >> k;
    for(int i=0;i<k;i++){
            cin >> box[i];
            sum+=box[i];
            }
          for(int i=k;i<n;i++){
                cin >> box[i];
                sum+=box[i]-box[i-k];
                if(sum>ans)ans=sum;
        }
    cout << ans <<endl;
return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x) {ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);


int main(){
	int n,k;
	cin>>n>>k;
	vi a(n);
	REP(i,n){
		cin>>a[i];
	}

	int sum=0;
	REP(i,k){
		sum+=a[i];
	}

	int ans=sum;
	FOR(i,k,n){
		sum+=a[i];
		sum-=a[i-k];
		ans=max(ans,sum);
	}

	cout<<ans<<endl;
}

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

int data[100000]={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++: #include <iostream>
using namespace std;
int main(){
	int n,m,a[100000],s,ms;
	while(cin >> n >> m,n){
		ms = s = 0;
		for(int i = 0;i < n;++i){
			cin >> a[i];
			if(i < m){
				ms += a[i];
				s += a[i];
			}
			else{
				s = s + a[i] - a[i - m];
				if(ms < s) ms = s;
			}
		}
		cout << ms << endl;
	}
	return 0;
}

C++: #include<cstdio>
using namespace std;
int num[100001];
int main(void){
   int n,k;
   while(scanf("%d%d",&n,&k),n+k){
      for(int i = 0;i < n;i++){
         scanf("%d",&num[i]);
      }
      int ma = -200000001;
      for(int i = 0;i <= n-k;i++){
         int part_ma = 0;
         for(int j = i;j < i+k;j++){
            part_ma += num[j];
         }
         if(ma > part_ma) ma = part_ma;
      }
      printf("%d\n",ma);
   }
   return 0;
}

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

#define rep(i, a, b) for(int i = (a); (i) < (b); i++)

using namespace std;

int main() {
	int n, k;
	while(cin >> n >> k, n) {
		vector<int> num;
		int tmp;
		rep(i, 0, n) {
			cin >> tmp;
			num.push_back(tmp);
		}

		int s = 0;
		rep(i, 1, n-k+1) {
			tmp = 0;
			rep(j, 0, k) {
				tmp += num[i+j-1];
			}

			if(s < tmp) s = tmp;
		}
	}

	cout << s << 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++){
        cin>> a[i];
    }

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

    cout<< ans<< endl;
}
    return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
#include<chrono>
#include<string>
#include<chrono>

using namespace std;






int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int nsize;
	int ksize;
	int a[100000];


	while (true) {
		cin >> nsize >> ksize;
		if (nsize == 0 && ksize == 0)break;
		for (int i = 0; i < nsize; i++) {
			cin >> a[i];
		}
		int maxval;
		int val = 0;
		for (int i = 0; i < ksize; i++) {
			val += a[i];
		}
		maxval = val;

		for (int i = ksize; i < nsize; i++) {
			val -= a[i - ksize];
			val += a[i];
			if (maxval < val) {
				maxval = val;
			}
		}
		cout << maxval << endl;
	}
	







	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main()
{
	while (1){
		int n, k;
		cin >> n >> k;
		if (!n and !k) return 0;
		int a[n];
		vector<int> max(n - k);
		REP(i, n) cin >> a[i];
		REP(i, k) max[0] += a[i];
		FOR(i, 1, n-k){
			max[i] = max[i-1] + a[i+k-1] - a[i-1];
		}

		sort(ALL(max), greater<int>());

		cout << max[0] << endl;
	}

}