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>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

int main(){
	int n, k;
	vector< int > a;
	vector< int > r;
	
	while(cin >> n >> k, n){
		a.RS(n);
		r.RS(n - k + 1);
		
		REP(i, n) cin >> a[i];
		
		REP(i, k) r[0] +=  a[i];
		
		FOR(i, k, n){
			r[i-k+1] = r[i-k] + a[i] - a[i-k];
		}
		cout << *max_element(ALL(r)) << endl;
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int n, k;
	int cnt, cnt_max = 0, masatoy;
	cin >> n >> k;
	while (n != 0 && k != 0) {
		for (int i = 1; i <= n; i++) {
			cin >> masatoy;
			if (1 <= i&&i <= n - k + 1) {
				cnt = 0;
				for (int j = 0; j < k - 1; j++) {
					cnt += masatoy + j;
				}
				//cout << cnt << endl;
				if (cnt > cnt_max) {
					cnt_max = cnt;
				}
			}
		}
		cout << cnt_max << endl;
		cnt_max = 0;
		cin >> n >> k;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
	for (;;){
		int a,b,c,d,max=0,m;
		cin>>a>>b;
		int e[a]={0};
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			cin>>e[c];
		}
		m=a-b;
		for (c=0;c<a-m;c++){
			for (int y=1;y<b;y++) e[c]=e[c]+e[c+y];
			if (max<e[c]) max=e[c];
	}
		cout<<max<<endl;
	}
	return 0;
}

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

int main()
{
int n,k;
cin >> n >> k;
while(n!=0||k!=0){
  int i=0, a[n], S[n-1];
  S[0] = 0;
  while(i < n){
    cin >> a[i];
    if (i>=1)
      S[i] = S[i-1]+a[i-1];
    i++;
  }
  i = 0;
  int m = S[k-1]-S[0];
  while(k+i<=n){
    if (m < S[i+k]-S[i])
      m = S[i+k]-S[i];
    i++;
  }
  cout << m << endl;
cin >> n >> k;
}}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    int N, k;
    cin >> N >> k;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
    	if(i < 3){
    	    total += a[i];
    	}else{
    	    total = total + a[i] - a[i-3];
    	}
	    if(ans < total){
	        ans = total;
	    }
    }
    cout << ans << endl;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int n,a[100001],k,sum,p;
int main(){
int i,j,h;
cin>>n>>k;
cin>>a[1];
for(i=2;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
for(i=1;i<=n;i++){
	for(j=i;i<=i+k;j++){
		p=a[i+k]-a[j];
		if(p>=sum){
			sum=p;
		}
	}
}
cout<<sum<<endl;
return 0;
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
  int n,k;
  scanf("%d%d\n",&n,&k );
  int a[100000];
  while (n) {
    for (int i = 0; i < n; i++) {
      scanf("%d\n",&a[i] );
    }
    int s = 0;
    for (int i = 0; i < k; i++) {
      s += a[i];
    }
    int ans = s;
    for (int i = k; i < n; i++) {
      s -= a[i - k];
      s += a[i];
      ans = max(ans,s);
    }
    printf("%d\n",ans );
    scanf("%d%d\n",&n,&k );
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec.at(i);
    }
    vector<int> rsw(n);
    rsw.at(0)=0;
    for(int i=1;i<=n;i++){
        rsw.at(i) = rsw.at(i-1) + vec.at(i-1);
    }
    int ans =0;
    for(int i =k;i<=n;i++){
        if(ans < rsw.at(i) - rsw.at(i-k)){
            ans = rsw.at(i) - rsw.at(i-k);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
	int n, k, num, ans, sam;
	
	while(cin >> n >> k)
	{
		if(!n && !k) break;
		queue<int> que;
		ans = 0;
		sam = 0;
		for(int i = 0; i < n; i++)
		{
			cin >> num;
			que.push(num);
			sam += num;
			if(que.size() == k )
			{
				if(ans < sam)
				{
					ans = sam;
				}
				sam -= que.front();
				que.pop();
			}
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	int n,k;
	int a[100001];
	while(cin >> n >> k, n){
		int ans = 0;
		rep(i,n){
			cin>>a[i];
		}
		rep(i,k)ans += a[i];
		int sum = 0;
		int tmp = ans;
		for(int i = k; i < n; i++){
			sum = tmp;
			sum -= a[i-k];
			sum += a[i];
			ans = max(ans,sum);
			tmp = sum;
		}
		FIN(ans);
	}

	return 0;
}

C++: #include <cstdio>

#define MAX(x, y) (x < y) ? y : x

int main(void)
{
	int n, k;
	int data[100000] = {0};
	
	while (1){
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) break;
		for (int i = 0; i < n; i++){
			scanf("%d", &data[i]);
		}
		
		for (int i = 0; i < n - 1; i++){
			if (data[j] < 0) data[j] *= 2;
		}
		
		for (int i = 0; i < n - 1; i++){
			data[i + 1] += data[i];
		}
		int max = 0;
		for (int i = 0; i <= (n - k); i++){
			int tmp = data[i + k] - data[i];
//			for (int j = i; j < (i + k); j++){
//				if (data[j] < 0) tmp += data[j];
//			}
			max = MAX(max, tmp);
		}
		
		/*
		int max = 0, tmp;
		for (int i = 0; i <= (n - k); i++){
			tmp = 0;
			for (int j = i; j < (i + k); j++){
				tmp += data[j];
			}
			max = MAX(max, tmp);
		}*/
		
		printf("%d\n", max);
	}
	
	return (0);
}

C++: #include<iostream>
#include<algorithm>
#define int long long int
using namespace std;

signed main()
{
	int n,k;
	while(cin>>n>>k,n){
	
	int a[100000];
	for(int i=0;i<n;i++)cin>>a[i];
	
	int s=0;
	for(int i=0;i<k;i++)s+=a[i];
	int ma=s;
	for(int i=k;i<n;i++)
	{
		s-=a[i-k];
		s+=a[i];
		ma=max(ma,s);
	}
	cout<<ma<<endl;}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <sstream>


using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;

int main(){

	int n,k;
	int a[100001];

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

	int ub,lb;
	ub=lb=0;
	ll cSum=0;
	for(int i = 0; i < k; i++){
		cSum += a[i];
	}
	ll maxSum = cSum;
	for(int i = 1; i <= n - k; i++){
		cSum -= a[i-1];
		cSum += a[i+k-1];
		maxSum = max(maxSum,cSum);
	}

	cout << maxSum << endl;

	int x;
	cin >> x;

	return 0;
}