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 <sstream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

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

bool has_key_using_count(map<char, char> &m, char n){
    if (m.count(n) == 0){
		//cout << "m doesn't have " << n << "." << endl;
        return false;
    }
    else{
        //cout << "m has " << n << "." << endl;
        return true;
    }
}

int main()
{
	//ifstream cin("sample.txt");

	int n = 0, k = 0, max = 0, tmp = 0, sumTmp = 0, maxTmp = 0;
	
	vector<int> series, seriesK, sum;

	while (cin >> n >> k) {
		if (n == 0 && k == 0) {
			break;
		}
		series.clear();
		seriesK.clear();
		sum.clear();
		// 読み込み
		//cin >> n >> k;
		rep(i, n) {
			cin >> tmp;
			series.push_back(tmp);
		}

		// 複数のseriesKの最大値を求める
		for (int i = 1; i < n-k+1; i++) {
			//seriesK.clear();
			sumTmp = 0;

			// Kまでの数列の和を計算する
			for (int j = i; j < i+k; j++) {
				//seriesK.push_back(series[j]);
				sumTmp += series[j];
			}

			// 和を求めて格納
			sum.push_back(sumTmp);

			// 現在の和の中で最大のものを計算
			if (sumTmp > maxTmp) {
				maxTmp = sumTmp;
			}
		}

		// 和の中で最大のものを出力
		/*rep(i, sum.size()) {
			if (sum[i] > max) {
				max = sum[i];
			}
		}*/

		// 出力する
		cout << maxTmp << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const int INF = 999999999;

int main() {
    int N, K;
    while(cin >> N >> K) {
        if(N == 0) break;
        vector<ll> a(N);
        for(int i = 0; i < N; ++i) cin >> a[i];

        vector<int> s(N+1, 0);
        for(int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

        ll res = -INF;
        for(int i = 0; i <= N-K; ++i) {
            ll val = s[K+i];
            if(res < val) res = val;
        }
        cout << res << endl;
    }

}

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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, k;
ll a[100100];
ll sum[100100];
vector<ll> ans;

int main(){
	while (cin >> n >> k&&n + k){
		fill(a, a + 100100, 0);
		fill(sum, sum + 100100, 0);
		ll MAX = -1000000000;
		REP(i, n)cin >> a[i];
		REP(i, n){
			if (i == 0)sum[i] = a[i];
			else sum[i] = sum[i - 1] + a[i];
		}
		ans.push_back(sum[k-1]);
		REP(i, n - k){
			ans.push_back(sum[i + k] - sum[i]);
		}
		REP(i, ans.size()){
			MAX = max(MAX, ans[i]);
		}
		cout << MAX << endl;
		ans.clear();
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long n,k;
	while(1){
		cin>>n>>k;
		if(!n && !k)break;
		vector<long long> sum;
		int num[n];
		rep(i,n)cin>>num[i];
		rep(i,n-k+1){
			long long alt=0;
			loop(j,i,i+k){
				alt+=num[j];
			}
			sum.push_back(alt);
		}
		sort(sum.begin(),sum.end());
		cout<<sum[sum.size()-1]<<endl;
	}
	return 0;
}

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

int main(){
  int serchn,numn;
  int gh = 0;
  vector<int> outp;
  for(int a = 0;;a++){
    cin >> numn >> serchn;
    if(numn == 0 && serchn == 0){
      break;
    }
    outp.resize(a+1,0);
    outp[a] = 0;
    gh = 0;
    vector<int> num(numn,0);
    for(int n = 0;n<numn;n++){
      cin >> num[n];
    }
    for(int n = 0;n<serchn;n++){
      outp[a] += num[n];
    }
    gh = outp[a];
    int b = serchn;
    for(int a = 0;b<numn;a++){
      gh += num[b];
      gh -= num[a];
      if(gh > outp[a]){
        outp[a] = gh;
      }
      b += 1;
    }
  }
  for(int b = 0;b<outp.size();b++){
    cout << outp[b] << endl;
  }
  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 <bits/stdc++.h>
using namespace std;
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
  const char* dlm = "";
  for(const auto& x:v) os << exchange(dlm, " ") << x;
  return os;
}
int32_t main(){
  vector<int32_t> a,s;
  size_t n,k; cin>>n>>k;
  while(n!=0||k!=0){
    a.resize(n);
    for(auto&& x:a) cin>>x;
    s.resize(n+1); s[0]=0;
    for(size_t i=1; i<n+1; ++i) s[i]=s[i-1]+a[i-1];
    int32_t ret=s[k]-s[0];
    for(size_t i=1; i<n-k; ++i) ret=max(ret,s[i+k]-s[i]);
    cout<<ret<<'\n';
    cin>>n>>k;
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  int gomi;
  cin >> gomi >> gomi;
  int mx = 0;
  int sum = 0;
  int left = 0;
  int right = k;
  for(int i = left; i < right; i++) {
    sum += a[i];
  }
  mx = sum;
  while(right < n) {
    left++;
    right++;
    sum = sum + a[right - 1] - a[left - 1];
    mx = max(sum, mx);
  }
  cout << mx << endl;
  return 0;
}

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

int main(){
  int numn,lisn,num;
  vector<int> outp;
  int outn = 1;
  for(int l = 0;;l++){
    cin >> numn >> lisn;
    if(numn == 0 && lisn == 0)break;
    outp.resize(l+1,0);
    vector<int> lists(numn,0);
    for(int n = 0;n<numn;n++){
      cin >> num;
      lists[n] = num;
    }
    for(int k = 0;k<numn-2;k++){
      outn = lists[k] + lists[k + 1] + lists[k + 2];
      if(outp[l] < outn){
        outp[l] = outn;
      }
    }
  }
  for(int q = 0;q<outp.size();q++){
    cout << outp[q] << " ";
  }
}