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

int main(){
  int n,k,a,s,m;
  while(cin>>n>>k,n||k){
    a=0;
    queue<int> q;
    n-=k;
    while(k--){
      cin>>s;
      a+=s;q.push(s);
    }
    m=a;
    while(n--){
      cin>>s;
      q.push(s);
      a=a+s-q.front();
      q.pop();
      m=max(m,a);
    }
    cout<<m<<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 = -2147483648;
        for (long i = 0; i < n - k; i++) {
            long result = 0;
            for (long l=i; l<i+k; l++)
                result += a[l];
            if (result > max)
                max = result;
        }
        printf("%ld\n", max);
    }
}

C++: #include<iostream>
#include<string.h>
using namespace std;
int main(){
	int i,i2,n,k,a[5001],max=-100000000,sum;
	cin>>n>>k;
	while(n!=0){
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=n-k+1;i++){
		sum=0;
		for(i2=i;i2<i+k;i2++)sum+=a[i2];
		if(sum>max){
			max=sum;
		}
	}
	cout<<max<<endl;
	cin>>n>>k;
	}
return 0;
}

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

#define INF (1e+9)
#define LLINF (1e+18)
#define LL long long


using namespace std;


int array[200000];

int main (void){
	//printf("%lld:::%lld",(LL)INF,(LL)LLINF);

	int n;
	int k;

	LL sum;
	LL maxNum;

	while(true){
		sum = 0;
		maxNum = -1*(LL)LLINF;
		scanf("%d",&n);
		scanf("%d",&k);
		if((n==0)||(k==0))break;
		for(int i=0;i<n;i++){
			scanf("%d",array+i);
		}
		for(int i=0;i<k;i++){
			sum += array[i];
		}
		maxNum = max(maxNum,sum);
		for(int i=0;i<n-1-k;i++){
			maxNum = max(maxNum,sum = (sum-array[i]+array[k]));
		}
		printf("%lld",maxNum);
	}

	return 0;
}

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

using namespace std;

long long int a[1000000];

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

C++: #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
  int n,k;
  cin>>n>>k;
  int a[100100];
  REP(i,n)cin>>a[i];
  int sum=0,ans=0;
  REP(i,n){
    if(i<k){
      sum+=a[i];
    }else{
      sum-=a[i-k];
      sum+=a[i];
    }
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
}

C++: #include <cstdio>

using namespace std;

typedef long long ll;

ll max1(ll a, ll b) { return a > b ? a : b; }

int main()
{
	ll n, k; scanf("%lld %lld", &n, &k);

	ll N[100001];

	for (ll i = 1; i <= n; ++i) scanf("%lld", &N[i]);

	ll sum = 0;

	for (ll i = 1; i <= k; ++i) sum += N[i];

	for (ll i = k; i < n; ++i) sum = max1(sum, sum - N[i-k+1] + N[i+1]);

	printf("%lld\n", sum);
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  while (1) {
    ll n, k;
    cin >> n >> k;
    if (n == 0 && k == 0) break;
    vector<ll> sum(n + 1, 0), a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) sum[i + 1] = sum[i] + a[i];
    ll ans = -LINF;
    rep(i, n - k + 1) ans = max(ans, sum[i + k] - sum[i]);
    cout << ans << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
using namespace std;
#define MAX_N 100000

unsigned long long int n, k, i, j, a[MAX_N], max = 0, f;

int sort(const void *a, const void *b){
  return *(int*)b - *(int*)a;
}

int main(){
  while(1){
    scanf("%lld %lld", &n, &k);
    if(n == 0 && k == 0) break;
    max = 0;
    for(i = 0; i < n; i++) scanf("%lld", &a[i]);
    for(i = 0; i < k; i++) max += a[i];
    f = max;
    for(i = 0; i < n - k; i++){
      f -= a[i];
      f += a[i + k];
      if(f > max) max = f;
    }
    printf("%lld\n", max);
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int ans=0,n,k,box[100005]={0},sum=0;;
        cin >> n >> k;
        if(n==0&&k==0)break;
        for(int i=0;i<k;i++){
            cin >> box[i];
            sum+=box[i];
            }
            ans=sum;
          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 <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
using namespace std;

int main()
{
	while (1)
	{
		int a = 0, b = 0;
		double c = -1000;
		cin >> a;
		cin >> b;
		if (a == 0 && b == 0)
		{
			break;
		}
		vector<double> size;
		vector<double> s;
		for (int i = 0; i < a; i++)
		{
			int w;
			cin >> w;
			size.push_back(w);
		}
		for (int i = 0; i < a - 2; i++)
		{
			double as = 0;
			for (int ii = 0; ii < b; ii++)
			{
				as += size[i + ii];
			}
			s.push_back(as);
		}
		for (int i = 0; i < a - 2; i++)
		{
			if (c < s[i])
			{
				c = s[i];
			}
		}
		cout << c << endl;
	}
	return 0;
}