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 <algorithm>

using namespace std;

int n,m;
int x,s;
int a[100000];

int main(void){

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

    for( int i = 0 ; i < n ; i++ ){
      cin >> a[i];
    }
    x = 0;
    for( int i = 0 ; i < n ; i++ ){
      x += a[i];
    }
    s = x;
    for( int i = 0 ; i < n - m ; i++ ){
      x -= a[i];
      x += a[i + m];
      if( s < x ) s = x;
    }

    cout << s << endl;

  }
  return 0;
}

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

using namespace std;

int main(){
  int a[100000] = {0};
  int n, k;
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int aa = 0;
  for(int i = 0; i < k; i++){
    aa += a[i];
  }
  //cout << "f:" << aa << endl;
  for(int i = k; i < n; i++){
    int aaa = aa - a[i - k] + a[i];
    aa = aaa > aa ? aaa : aa;
    //cout << "f:" << aa << " n:" << aaa << endl;
  }
  cout << aa << endl;
  return 0;
}

C++: #include<cstdio>
#include<utility>
#include<algorithm>
#define INF INT_MAX/2-1
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int a[100000];
int main(){
	int n, k;
	while (scanf("%d%d", &n, &k), n){
		rep(i, n)
			scanf("%d", &a[i]);
		int Max = -INF;
		rep(i, n - k + 1){
			int sum = 0;
			rep(j, k){
				sum += a[i + j];
			}
			Max = max(Max, sum);
		}
		printf("%d\n", Max);
	}
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
#define INF 114514
using namespace std;




int main(){
	while (1) {
		long long n, k, now = 0, m = 0, i;
		long long a[100009];
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
		for (i = 1; i <= n; i++) {
			cin >> a[i];
		}
		for (i = 1; i <= k; i++) {
			now += a[i];
		}
		m = now;
		for (i = 1; i <= n - k; i++) {
			now = now - a[i] + a[i + k];
			if (now > m) m = now;
		}
		cout << m << endl;
	}
	return 0;
}

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

using namespace std;

int n,m;
int x,s;
int a[100000];

int main(void){

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

    for( int i = 0 ; i < n ; i++ ){
      cin >> a[i];
    }
    x = a[0] + a[1] + a[2];
    s = x;
    for( int i = 0 ; i < n - m ; i++ ){
      x -= a[i];
      x += a[i + m];
      if( s < x ) s = x;
    }

    cout << s << endl;

  }
  return 0;
}

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

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

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

int main(){
	int n, k;
	scanf("%d %d", &n,&k);
	vector<int> data(MAX_N);
	for( int i=0; i<n; i++ ){
		scanf("%d", &data[i]);
	}
	int ans = 0;
	for( int i=0; i<n-k; i++ ){
		int sum = data[i] + data[i+1] + data[i+2];
		ans = max(ans, sum);
	}
	printf("%d\n", ans);
}

C++: #include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9

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

int n,k,a[100000];

int main(){
	while(cin>>n>>k&&n){
		rep(i,n)cin>>a[i];
		int s=0;
		rep(i,k)s+=a[i];
		int ans=s;
		rep(i,n-k){
			s+=a[k+i]-a[i];
			ans=max(ans,s);
		}
		cout<<ans<<endl;
	}
}

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

int N, K, a[1000000];
int main()
{
  while(true)
  {
    cin >> N >> K;
    if(!N)
      break;
    int v = 0;
    for(int i = 0; i < N; i++)
    {
      cin >> a[i];
      if(i < K)
        v += a[i];
    }
    int ans = v;
    for(int i = K; i < N; i++)
      ans = max(ans, v = v + a[i] - a[i - K]);
    cout << ans << endl;
  }
}

C++: #include <stdio.h>
#include <string.h>

#define MAX_BIT_SIZE 100001

int BIT[MAX_BIT_SIZE];
int n;

int sum(int index) {
    int ret = 0;

    while (index > 0) {
        ret += BIT[index];
        index -= index & -index;
    }

    return ret;
}

void add(int index, int value) {
    int i = 1;
    while (index <= n) {
        BIT[index] += value;
        printf("%d\n", index);
        index += i;
        i <<= 1;
    }
}

int main() {
    while (1) {
        int k;
        int i;
        int max_count = 0;


        scanf("%d %d", &n, &k);
        if (n == 0 && k == 0) return 0;

        memset(BIT, 0, MAX_BIT_SIZE);

        for (i=0;i<n;i++) {
            int d;
            scanf("%d", &d);
            add(i, d);
        }

        for (i=0;i<n-k;i++) {
            int now_count = sum(i+k) - sum(i);
            if (now_count > max_count)max_count = now_count;
        }

        printf("%d\n", max_count);
    }
}

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

int main(){
	int n,k,max,buf,*a;
	
	while(1){
		cin >> n >> k;
		
		if(n || k){
			max = buf = 0;
			
			a = new int[n];
			
			for(int i = 0; i < n; i++){
				cin >> a[i];
			}
			
			for(int i = 0; i < k-1; i++){
				buf += a[i];
			}
			
			for(int i = k-1; i < n; i++){
				buf += a[i];
				max = (max < buf)?buf:max;
				buf -= a[i-k+1];
			}
			
			cout << max << endl;
		}else{
			break;
		}
	}
	
	return 0;
}

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

int main()
{
	int n, k, i, inp, sum, max=0;
	int *a;
	cin >> n >> k;
	a = new int[n];
	
	for (i = 0; i < n; i++){
		cin >> inp;
		a[i] = inp;
	}
	
	int o1, o2;
	cin >> o1 >> o2;

	for (i = 0; i < n - 2; i++){
		sum = a[i] + a[i + 1] + a[i + 2];
		if (sum > max){ max = sum; }
	}

	cout << max << endl;

	delete[] a; 
	return 0;
}