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<stdio.h>
int main()
{
	int a[100000],n,k,r,s,i;
	while(scanf("%d%d",&n,&k),n)
	{
		for(i=0;i<n;++i)scanf("%d",&a[i]);
		for(s=r=i=0;i<k;++i)s+=a[i];
		for(i=k;i<n;++i)s=s-a[i-k]+a[i],r<s?r=s:0;
		printf("%d\n",r);
	}
}

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

int main(){
	int n, k;
	while( scanf("%d %d", &n, &k), n && k ){
		//scanf("%d %d", &n, &k);
		vector<int> data(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 = 0;
			for( int j=0; j<k; j++ ) sum += data[i+j];
			ans = max(ans, sum);
		}
		printf("%d\n", ans);
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k,x=0,ma=0;
	cin>>n>>k;
	int a[5];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n-k-+1;i++){
		for(int j=0;j<k;j++){
			x+=a[i+k];
		}
		ma=max(ma,x);
	}
	cout<<ma<<endl;
return 0;
}

C++: #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int INF=1e9;
int main(){
  ll n,k;
  cin>>n>>k;
  ll a[100100];
  REP(i,n)cin>>a[i];
  ll sum=0,ans=0;
  REP(i,n){
    if(i<k){
      sum+=a[i];
    }else{
      sum-=a[i-k];
      sum+=a[i];
    }
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
typedef long long ll;
// using i32=int;using i64=long long;using ll =i64;
// using uint=unsigned int;using ull=unsigned long long;
// template<typename T> using matrix=vector<vector<T> >;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//config
//#undef NDEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T mod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}

ll INF=1LL<<58;
class Main{
public:
	void run(){
		while(true){
			int N,K;scanf("%d %d",&N,&K);
			if(N==0)break;
			vector<int> as(N);REP(i,N)scanf("%d",&as[i]);

			vector<ll> imos(N+1);
			for(int v=1;v<=N;v++)imos[v]=imos[v-1]+as[v-1];

			ll Mv=-INF;
			for(int i=0;i<=N;i++){
				if(i+K<=N)Mv=max(Mv,imos[i+K]-imos[i]);
			}
			cout <<Mv<<endl;
		}
	}
};
int main(){
  	Main().run();
  	return 0;
 }

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n = 0, k = 0;
int a[100001] = {}, b[100001] = {};
int ans;
int main(){
	while (true){
		n = 0; k = 0;
		ans = 0;
		cin >> n >> k;
		if (n == 0 || k == 0)	break;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
		}
		for (int x = 0; x<k; x++){
			b[1] += a[x + 1];
		}
		ans = b[1];
		for (int i = 2; i <= n; i++){
			if ((i+k)==(n+1))	break;
			b[i] = b[i - 1] - a[i - 1] + a[i + k - 1];
			ans = max(b[i], ans);
		}
		cout << ans << endl;
	}
	return 0;
}

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

typedef long long ll;

int main(void)
{
    int n, k;
    while(1)
    {
        cin >> n >> k;
        if(n == 0 and k == 0) return 0;
        vector<ll> a(n+1, 0);
        rep(i, n)
        {
            int x; cin >> x;
            a[i+1] = a[i] + x;
        }
        ll ans = -1e18;
        rep(i, n)
        {   
            if(i + k > n) continue; 
            ans = max(ans, a[i+k] - a[i]);
        }
        cout << ans << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7
#define eb emplace_back

int main() {
    int n, k;
    while (cin >> n >> k) {
        if (n == 0 && k == 0) break;
        int a[n]; rep(i, n) cin >> a[i];
        int sum[n + 1]; sum[0] = 0;
        rep(i, n) sum[i + 1] = sum[i] + a[i];
        int ans = -inf;
        rep(i, n) {
            int left = i;
            int right = min(i + k, n);
            if (i + k >= n) break;
            chmax(ans, sum[right] - sum[left]);
        }
        cout << ans << endl;
    }
}