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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, k;
ll a[100100];
ll sum[100100];

int main(){
	while (cin >> n >> k&&n + k){
		fill(a, a + 100100, 0);
		fill(sum, sum + 100100, 0);
		ll MAX = -1000000000;
		REP(i, n)cin >> a[i];
		REP(i, n){
			if (i == 0)sum[i] = a[i];
			else sum[i] = sum[i - 1] + a[i];
		}
		REP(i, n - k + 1){
			sum[i + k] -= sum[i];
		}
		FOR(i, k - 1, n){
			MAX = max(MAX, sum[i]);
		}
		cout << MAX << endl;
	}
}

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

using namespace std;

class bit{
	
	public:
	vector<int> v;
	int n;

	bit(int arg){
		n = arg;
		//initially all nodes are 0
		for(int i=0;i<n+1;i++){
			v.push_back(0);
		}
	}
	
	int sum(int i){
		int s = 0;
		while(i>0){
			s += v[i];
			i -= i & -i;
		}
		return s;
	}
	
	void add(int i, int x){
		while(i <= n){
			v[i] += x;
			i += i & -i;
		}
	}
};

int main(void){
	int n,k;
	
	while(cin >> n >> k){
		if((n|k) == 0) break;
		
		bit b = bit(n);
		int tmp;
		vector<int> sumvec;

		//construct Binary Index Tree
		for(int i=1;i<=n;i++){
			cin >> tmp;
			b.add(i,tmp);
			//cerr << "added " << tmp << endl;
		}
		
		sumvec.push_back(0);
		//calculate sum
		for(int i=1;i<=n;i++){
			sumvec.push_back(b.sum(i));
			//cerr << sumvec[i] << endl;
		}
		
		int maxi = 0;
		for(int i=1;i<=n-k;i++){
			maxi = max(maxi, sumvec[i+k] - sumvec[i]);
		}
		
		cout << maxi << endl;
	}
}

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

using namespace std;

int suretu[100000];

int ret_maxsum(int n, int k)
{
	int temp = 0;
	int max = 0, cont = 0;
	
	for(int i = 0; i < n-k+1; i++){
		for(int j = 0; j < k; j++){
			temp += suretu[cont+j];
//			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 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];
		}
		
		cout << ret_maxsum(n, k) << endl;
	}
	
}

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 sum=0;
      int i;
      for(i=0;i<k;i++)
	{
	  sum+=d[i];
	}
      int max=sum;
      for(;i<n;i++)
	{
	  sum+=d[i];
	  sum-=d[i-k];
	  if(max<sum)
	    max=sum;
	}

      cout<<max<<endl;
    }
}

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


int sum(int a[], int num) {
  int tmp = 0;
  for(int i = 0; i < num; i++) {
    tmp += a[i];
  }
  return tmp;
}

main() {
  while(1) {
    int n, k;
    cin >> n >> k;
    if(n == 0 && k == 0) break;
    int buf[k];
    int maxS = -INF;
    for(int i = 0; i < n; i++) {
      for(int j = 0; j+1 < k; j++) buf[j] = buf[j+1];
      cin >> buf[k-1];
      if(i+1 < k) continue;
      int tmp = sum(buf, k);
      if(maxS == -INF || tmp > maxS) maxS = tmp;
    }
    cout << maxS << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(void){
    for(;;){
	int n,k;
	int sum=0,sum2=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<n-k+1;i++){
        sum=0;
        for(int j=0;j<k;j++){
            sum +=a[j+i];
        }
        if(sum2<sum)sum2=sum;
    }
    cout << sum2 << endl;

    }


	return 0;
}

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

using namespace std;

int a[100000 + 1];
int s[100000 + 1];

int main() {

	int n, k;
	int i, j, l;
	int sum = 0, asus = 0;

	while (true) {

		memset(s, 0, sizeof(s));
		memset(a, 0, sizeof(a));

		cin >> n >> k;
		if (n == 0 && k == 0) return 0;

		for (i = 0; i < n; ++i) cin >> a[i];

		for (i = 0; i < n-k; ++i) {
			for (j = 0; j < k; ++j) {

				sum += a[i + j];
			}
			asus = max(asus, sum);
			sum = 0;
		}

		cout << asus << endl;
	}
}

C++: #include <cstdio>

int n,k,a;
long long dp[100000];

int main(){
	while(scanf("%d%d",&n,&k), n != 0){
		for(int i = 0; i < n; i++) dp[i] = 0;
		for(int i = 0; i < n; i++){
			scanf("%d",&a);
			if(i == 0){
				dp[i] = a;
			}
			else{
				dp[i] = dp[i-1] + a;
			}
		}
		long long mx = 0;
		for(int i = 0; i <= n - k; i++){
			long long sum = dp[i+k] - dp[i];
			if(sum > mx){
				mx = sum;
			}
		}
		printf("%lld\n",mx);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <array>
#include <set>
#include <string>
#include <numeric>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < n; i++)



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

    for(;;) {
        int n, k;
        std::cin >> n >> k;
        if (n == 0 && k == 0) break;
        std::vector<long long int> num(n);
        rep(i, n) std::cin >> num.at(i);

        long long int sum = std::accumulate(num.begin(),num.begin()+k,0LL);
        rep(i,n-k) sum = std::max(sum,sum-num.at(i)+num.at(k+i));

        std::cout << sum << "\n";
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long n,k;
	while(1){
		cin>>n>>k;
		if(!n && !k)break;
		int data[n];
		long long sum[n-k+1];
		sum[0]=0;
		rep(i,n){
			cin>>data[i];
			if(i<k)sum[0]+=data[i];
		}
		rep(i,n-k){
			sum[i+1]=sum[i]+data[i+k]-data[i];
		}
		sort(sum,sum+n-k+1);
		cout<<sum[n-k]<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<string>
#include<vector>
#include<sstream>
#include<deque>
#include<algorithm>
#include<queue>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)

int ini[10001];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	rep(i,n){
		scanf("%d",&ini[i]);
	}
	
	int sum=0;
	rep(i,m){
		sum+=ini[i];
	}
	
	int maxi=sum;
	for(int i=m;i<n;i++){
		sum-=ini[i-m];
		sum+=ini[i];
		maxi=max(maxi,sum);
	}
	
	printf("%d\n",maxi);
}

C++: #include<stdio.h>
int ar[100000];
int max(int a,int b){return a>b?a:b;}
int main(){
	int n,k;
	int i,j;
	while(1){
	int ans=0;
	scanf("%d %d",&n,&k);
	if(n==0)return 0;
	for(i=0;i<n;i++)scanf("%d",&ar[i]);
	int res=0;
	for(i=0;i<k;i++)res+=ar[i];
	ans=max(ans,res);
	for(i=k;i<n;i++){
		res+=ar[i];
		res-=ar[i-k];
		ans=max(ans,res);
	}
	printf("%d\n",ans);
	}
}