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 <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 = -10000000000;
	ans = *max_element(sums.begin(), sums.begin() + k);
	for (int i = 1; i + k < n; i++)
	{
		ans = max(ans, sums[i + k - 1] - sums[i - 1]);
	}
	cout << ans << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
using namespace std;

int main()
{
    int n, k, index;
    long a[100005];
    long suma[100005];
    long ans[10];
    index = 0;
    REP(i, 10){
        cin >> n >> k;
        if(n == 0 && k == 0)
            break;
        REP(j, n)
            cin >> a[j];
        suma[0] = 0;
        REP(j, n)
            suma[j+1] = suma[j] + a[j];
        REP(j, n-k+1){
            if(j==0)
                ans[index] = suma[j+k] - suma[j];
            else{
                if(ans[index] < (suma[j+k] - suma[j]))
                    ans[index] = suma[j+k] - suma[j];
            }
        }
        index++;
    }
    REP(i, index)
        cout << ans[i] << endl;

    
    

    return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int main(){
  int n,k,a,max;
  int set[100001];
  while(1){
  cin >> 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 <bits/stdc++.h>
using namespace std;
using ll = long long;

int k, m, n, h, w;
ll t[1 << 17], d[1 << 17];

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#define rep(i,a) for(int i=0;i<(a);++i)

int n, k;
int a[100001], sum[100001];

int main(){
	while (scanf("%d%d", &n, &k), n|k){
		rep(i, 100001)sum[i] = 0;
		scanf("%d", &a[0]);
		for (int i = 1; i < n; ++i){
			scanf("%d", &a[i]);
			sum[i] = sum[i - 1] + a[i];
		}
		int ans = 0;
		for (int i = 0; i < n - k; ++i){
			ans = std::max(ans, sum[i + k] - sum[i]);
		}
		printf("%d\n", ans);
	}
	return 0;
}

C++: #include<stdio.h>

#include<algorithm>


using namespace std ;



int main()
{
	int n ,k ;

	while( 1 )
	{
		scanf( "%d %d" ,&n ,&k ) ;


		if( !( n | k ) )
		{
			return 0 ;
		}


		int if_k = k - 1 ;

		int ans = -10001 ,other[ 100000 ] ;
		
		int sum = 0 ;

		int i ;
		for( i = 0 ; i < n ; ++i )
		{
			scanf( "%d" ,&other[ i ] ) ;

			sum += other[ i ] ;


			if( i > if_k )
			{
				sum -= other[ i - k ] ;
			}

			if( i >= if_k )
			{
				ans = max( ans ,sum ) ;
			}
		}


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

C++: // tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
inline void modAdd(int& _a, int _b, int _m) { _a = (_a + _b) % _m; }
inline void modAdd(lint& _a, lint _b, lint _m) { _a = (_a + _b) % _m; }
inline void minUpdate(int& _a, int _b) { _a = min(_a, _b); }
inline void minUpdate(lint& _a, lint _b) { _a = min(_a, _b); }
inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }
inline void maxUpdate(lint& _a, lint _b) { _a = max(_a, _b); }

int n, k, a[100010];

void solve() {
	for_(i,1,n) a[i] = a[i] +  a[i - 1];
	int ans = a[k - 1];
	for_(i,k,n) maxUpdate(ans, a[i] - a[i - k]);
	printf("%d\n", ans);;
}

int main() {
	while (cin >> n >> k, n) {
		for_(i,0,n) scanf("%d", &a[i]);
		solve();
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

int stage[16][16];
int bit[100001];

int sumBIT(int i,int* bit){
	int s = 0;
	while(i > 0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void addBIT(int i, int x,int* bit,int n){
	while(i <= n){
		bit[i] += x;
		i += i & -i;
	}	
}


int main(){
	int n,k;
	while(~scanf("%d %d",&n,&k)){
		if(n==k && k==0) break;
		memset(bit,0,sizeof(bit));
		for(int i=0;i<n;i++){
			int num;
			scanf("%d",&num);
			addBIT(i+1,num,bit,100000);
		}

		int res = numeric_limits<int>::min();
		for(int i=1;i+2<=n;i++){
			res = max(sumBIT(i+2,bit) - sumBIT(i-1,bit),res);
		}

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

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

int n, k;
int a[100000];

signed main()
{
	while (true) {
		cin >> n >> k;
		if (n == 0 && k == 0) break;
		rep(i,n) cin >> a[i];

		int mx;
		int sum = 0;
		rep(i,k) {
			sum += a[i];
		}
		mx = sum;
		//cout << "first = " << mx << endl;

		for (int i=0; i<=n-k -1; i++) {
			sum -= a[i];
			sum += a[i+k];
			//printf("i = %d, sum = %d\n", i, sum);
			mx = max(mx, sum);
		}

		cout << mx << endl;
	}
}