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

int main()
{
    long long n,m;
    long long a[100008];
    while(~scanf("%lld%lld",&n,&m))
    {
        long long sum = 0;
        long long temp = -1000000001;
        for(int i=0;i<n;i++) scanf("%lld",&a[i]);
        int cap = 0;
        for(int i=0;i<n;i++)
        {
            if(cap!=m) {sum += a[i]; cap++;}
            else sum += a[i]-a[i-3];
            printf("--%lld\n",sum);
            if(sum>temp) temp=sum;
        }
        printf("%lld\n",temp);
    }
    return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n, k;
  while (cin >> n >> k, n) {
    vi v(n);
    rep(i, n) cin >> v[i];
    int s    = accumulate(v.begin(), v.begin() + k, 0);
    int maxi = s;
    rep(i, n - k) {
      s += v[i + k] - v[i];
      cmax(maxi, s);
    }
    cout << maxi << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;

long long int sum,k,n,num[200000];

int main(){

    while(1){

    long long int ans=-100000000000;
    cin >> n >> k;
    if(n==0&&k==0)break;

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

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

    for(int i=k;i<n;i++){
        if(ans<sum)ans=sum;
        sum-=num[i-k];
        sum+=num[i];
    }

    cout << ans << endl;
    }


return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define loop(i,n) for(int i=0;i<n;i++)
#define loop2(i,s,n) for(int i=s;i<n;i++)
int s[100002];

int main(){
  while(1){
    int n,k;
    cin>>n>>k;
    if(n==0)return 0;
    loop(i,n){
      cin>>s[i];
      if(i>=1)s[i]+=s[i-1];
      if(i>=k)s[i]-=s[i-k];
    }
    int m=0;
    loop2(i,k-1,n){
      m=max(m,s[i]);
    }
    cout<<m<<endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;


int main() {

  int n,k;
  int a[100001];

  int max;
  int sum_seq;


  while(cin >> n >> k) {

    if(n==0 && k==0) break;

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

    max=0;

    sum_seq=0;

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

    for(int i=0;i<=n-k;i++) {

      if(max<sum_seq) max=sum_seq;

      if(i!=n-k) sum_seq+=a[i+k]-a[i];

    }

    cout << max << endl;

  }

  return 0;

}

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

unsigned long long int n, k, i, j, a[MAX_N], max = 0, f;

int sort(const void *a, const void *b){
  return *(int*)b - *(int*)a;
}

int main(){
  while(1){
    scanf("%lld %lld", &n, &k);
    if(n == 0 && k == 0) break;
    max = 0;
    for(i = 0; i < n; i++) scanf("%lld", &a[i]);
    for(i = 0; i < k; i++) max += a[i];
    f = max;
    for(i = 0; i < n - k - 1; i++){
      f -= a[i];
      f += a[i + k];
      if(f > max) max = f;
    }
    printf("%lld\n", max);
  }
  return 0;
}

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 - 1];
	int ans = a[k - 1];
	for_(i,k,n) maxUpdate(ans, a[i] - a[i - k]);
	cout << ans << endl;
}

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

C++: #include<iostream>
#include<vector>
using namespace std;
#define MAX 100001
int main(void){
  int n , k;
  while(cin>>n>>k,n+k){
  int in[MAX];
  int dp[MAX];
  for(int i = 0 ; i < n ; i ++) 
    cin>>in[i];
  for(int i = 1 ; i < n ; i ++){
    dp[i] = in[i - 1] + in[i];
  }
  int res = -(1<<22);
  for(int i = 2 ; i < n ; i ++){
    res = max(res,in[i] + dp[i - 1]);
    //cout<<in[i] <<" " << dp[i - 1] << endl;
  }
  
  
  cout<<res<<endl;
  }
}