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;

int main(){
	int n, k, x, maxnum = 0;
	cin >> n >> k;
	int wa[199999];
	for(int i=0;i<199999;i++) wa[i] = 0;
	for(int i=0;i<n;i++){
		cin >> x;
		for(int j=0;j<k;j++){
			wa[i+j] += x;
		}
	}
	cin >> x >> x;
	for(int i=k-1;i<n;i++){
		if(maxnum < wa[i]) maxnum = wa[i];
	}
	cout << maxnum;
}

C++: #include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;

int s[100000 + 1];

int main(){
	while (1) {
		int n, k,ans=0;
		cin >> n >> k;
		if (n == 0) break;
		for (int i = 0; i < n; i++) cin >> s[i];

		for (int i = 0; i < n-2; i++) {
			ans = max(ans, s[i] + s[i + 1]+ s[i + 2]);
		}
		cout << ans << endl;
	}
	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++){
			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 <algorithm>
#include <vector>
using namespace std;

int main() {
	int n, k, tmp;
	while (cin >> n >> k, n||k) {
		vector<int> dt, ans;
		for (int i=0; i<n; i++) {
			cin >> tmp;
			dt.push_back(tmp);
			if (i > 1) {
				int sum = 0;
				for(int j=k; j>0; j--)
					sum += dt[i-j+1];
				ans.push_back(sum);
			}
		}
		sort(ans.rbegin(), ans.rend());
		cout << ans[0] << endl;
	}

	return 0;
}

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;i++,sum=0){
    for(int j=i;j<i+k;j++){
      sum += set[j];
    }
    if(max<sum || i==1){
      max=sum;
    }
  }
  printf("%d\n",max);
  }
}

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

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

int main(){

	int n,k,s,data;
	s = 0;
	
	while(cin >> n,n){
	cin >> k;
	vector<int> sum;	

	rep(i,n){
		cin >> data;
		sum.push_back(data);
	}

	rep(i,k){
		if( s < sum[i] + sum[i+1] + sum[i+2]) s = sum[i] + sum[i+1] + sum[i+2];
	}

	cout << s << endl;
	}
	
	return 0;
}

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;
	while(cin >> n >> k, n){
		int a[n];
		int ans = 0;
		rep(i,n){
			cin>>a[i];
			if(i >= k-1){
				int tmp = 0;
				rep(j,k){
					tmp += a[i-j];
				}
				ans = max(ans,tmp);
			}
		}
		FIN(ans);
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
constexpr int MAX_N=100000;

int n,k;
int a[MAX_N];
long long int sum=0;
long long int res=0;

int main(){
    while(1){
        std::cin>>n>>k;
        if(n+k==0)
            break;

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

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

        for(int i=0;i<n-k-1;++i){
            sum-=a[i];
            sum+=a[k];
            res=std::max(res,sum);
        }
        std::cout<<res<<std::endl;
    }
    return 0;
}

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

using namespace std;

int main(){

	int n,k,a[100000],sum,ans;

	while(cin>>n>>k,n||k){

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

	sum=0;

    for(int i=0;i<k;i++){
    	sum=sum+a[i];
    }

    ans=sum;

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

    cout<<ans<<endl;


	}
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 1000000009;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int t, d; };

int main()
{
	int n, k; cin >> n >> k;
	vector<LL> sums(n);
	rep(i, n)
	{
		cin >> sums[i];
		if (i != 0)
			sums[i] += sums[i - 1];
	}
	LL ans = sums[k];
	for (int i = 0; i + k < n; i++)
	{
		ans = max(ans, sums[i + k - 1] - sums[i - 1]);
	}
	cout << ans << endl;
	return 0;
}

C++: #include<iostream>
main(){for(intn,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))for(M=1<<31,i=s=0;i<n;s+=a[i++],k<i&&(s-=a[ik-1]),M<s&&(M=s))std::cin>>a[i];}