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 <algorithm>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int n, k;
int ary[100000];

int main() {
	while(1) {
		scanf(" %d %d", &n, &k);
		if(n == 0 && k == 0) break;
		memset(ary, 0, sizeof ary);
		rep(i,n) {
			static int t;
			scanf(" %d", &t);
			ary[i] = t;
		}

		int sum = 0;
		for(int i = 0; i < k; i++) sum += ary[i];

		int maxv = sum;
		for(int i = 1; i < n - k + 1; i++) {
			sum -= ary[i - 1];
			sum += ary[i + k - 1];
			maxv = max<int>(maxv, sum);
		}
		printf("%d\n", maxv);
	}
	return 0;
}

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

long long int sum,k,n,num[200000];

int main(){

    while(1){

    long long int ans=-1000000000000;
    cin >> n >> k;
    if(n==0&&k==0)break;

    for(int i=0;i<n;i++){
        cin  >> num[i];
    }

    for(int i=0;i<n-k;i++){
        for(int j=i;j<i+k;j++){
            sum+=num[j];
        }
        if(ans<sum)ans=sum;
        sum=0;

    }

    cout << ans << endl;
    }


return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int N, K;
int num[100000];
int tmp[100000];

int main() {
	while(scanf("%d %d", &N, &K), N || K) {
		rep(i, N) scanf("%d", &num[i]);
		FOR(i, 1, N) num[i] += num[i - 1];
		int ans = num[K - 1];
		FOR(i, K, N) ans = max(num[i] - num[i - K], ans);
		printf("%d\n", ans);
	}
	return 0;
}

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

template<typename T>
struct CumulativeSum {
    vector<T> s;
    CumulativeSum(const vector<T> &nums) {
        int n = nums.size();
        s.resize(n + 1, 0);
        for (int i = 0; i < n; ++i) {
            s[i + 1] = s[i] + nums[i];
        }
    }
    // [l, r), l and r is 0-indexed.
    T sum(int l, int r) {
        return s[r] - s[l];
    }
};

/*
    verified https://onlinejudge.u-aizu.ac.jp/problems/0516
*/
int main() {
    int n, k;
    vector< long long > ress;
    while (cin >> n >> k) {
        if (n == 0) break;
        vector<long long> nums(n);
        for (int i = 0; i < n; ++i) cin >> nums[i];
        CumulativeSum<long long> cs(nums);
        long long res = numeric_limits<long long>::min();
        for (int i = 0; i <= n - k; ++i) {
            long long val = cs.sum(i, i + k);
            res = max(res, val);
        }
        ress.push_back(res);
    }
    for (long long res : ress) cout << res << endl;
}

C++: #include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int n,k,a,max;
  int set[100001];
  while(1){
    scanf("%d %d",&n,&k);
  if(n==0 && k==0)break;
  max=0;
  for(int i=0;i<n;i++){
    scanf("%d",&set[i]);
  }

  for(int i=0,sum=0;i<n-k+1;i++,sum=0){
    for(int j=i,l=i+k-1;;j++,l--){
      sum += set[j]+set[l];
      if(l-j==1){
	break;
      }else if(l==j){
	sum-=set[j];
	break;
      }
    }
    if(max<sum || i==1){
      max=sum;
    }
  }
  printf("%d\n",max);
  }
}

C++: #include <iostream>
using namespace std;
int main(){
	int s[100000];
	int n;
	int k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	int q=0;
	for(int i=0;i+k-1<=n;i++){
		int t=0;
		for(int ii=0;ii<k;ii++){
			t+=s[i+ii];
		}
		if(q<t)
			q=t;
	}
	cout<<q<<endl;
	return 0;
}

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

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

    int n, k;
    while(cin >> n >> k){
        if(n == 0 and k == 0) break;
        vector<int> A(n), B(n + 1, 0);
        for(int i = 0; i < n; i++){
            cin >> A[i];
            B[i + 1] += B[i] + (i > 0 ? A[i - 1] : 0);
        }

        int maxi = -1e9;
        for(int i = k; i < n + 1; i++){
            maxi = max(maxi, B[i] - B[i - k]);
        }
        cout << maxi << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

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

int main(){
  int n,k,x;
  vector<int> s;
  int start,end,ans=0,sum;
  
  while(1){

    cin>>n>>k;
    for(int i=0;i<n;i++){
      cin>>x;
      s.push_back(x);
    }
  
    start=0;end=k;
    while(end-1<n){
      sum=0;
      for(int i=start;i<end;i++){
        sum+=s[i];
      }
      ans=max(ans,sum);
    
      start++;end++;
    }
  
    printf("%d\n",ans);
    ans=0;
    s.clear();
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#define MAX 100000
using namespace std;

int a[MAX];

int main(void){
 	int n,k;
	while(cin >> n >> k,n|k){
		int ans=-1000000000;
		int cmax=0;
		for(int i=0;i<k;i++){
			cin >> a[i];
			cmax+=a[i];
		}
		ans=max(ans,cmax);
		for(int i=k;i<n;i++){
			cin >> a[i];
			cmax+=a[i];
			cmax-=a[i-k];
			ans=max(ans,cmax);
		}
		cout << ans << endl;
	}
	return 0;
}