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 main(){
  long long n,k;

  while(1) {
    ans=-1000000000;
    cin>>n>>k;
    if(n == 0 and k == 0) break;
    long long a[n];for(int i=0;i<n;i++)cin>>a[i];

    for(int i=0;i<n-k+1;i++){
      long long temp=0;
      for(int j=i;j<i+k;j++){
        temp+=a[j];
      }
      ans=max(temp,ans);
    }
    cout<<ans<<endl;
  }
}

C++: #include<iostream>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M)){for(i=s=0;i<n;i++<k&&(M=s+=a[i-1]))std::cin>>a[i];for(i=k;i<n;M<s&&(M=s))s+=a[i]-a[i++-k];}}

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; i++){
      f -= a[i];
      f += a[i + k];
      if(f > max) max = f;
    }
    printf("%lld\n", max);
  }
  return 0;
}

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

int main(){
	int n, k;
	int num[100000];
	int sum = 0;
	int maxsum = 0;
	
	for(;;){
		cin >> n >> k;
		maxsum = sum = 0;
		if(n == 0 && k == 0)	return 0;
			for(int i = 0; i < n; i++){
				cin >> num[i];
			}
		for(int i = 0; i < n-k; i++){
			sum = 0;
			for(int j = i; j < i+k; j++){
				sum += num[j];
			}
			maxsum = max(maxsum, sum);
		}
	
		cout << maxsum << endl;
	}
	
	return 0;
}

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

//{{{
/********************************************************************/
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) elems.push_back(item);
      item.clear();
    }
    else item += ch;
  }
  if (!item.empty()) elems.push_back(item);
  return elems;
}

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

/****************************************************************/
//}}}

signed main()
{
  int n, m;

  while (cin >> n >> m, n + m){
    int a[n];
    long long int maxsum = 0;

    rep(i, n) a[i] = in();
    rep(i, m) maxsum += a[i];
    reps(i, m, n) maxsum = max(maxsum, maxsum - a[i - m] + a[i]);
    print(maxsum);
  }

  return (0);
}

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

ll a[100001];
ll memo[100001];//i???????????§?¶?????????????????¨?(i???????????????)
int main(){
	int n, k;
	while (scanf("%d%d", &n, &k), n){
		rep(i, n)
			scanf("%lld", &a[i]);
		ll sum = 0;
		rep(i, n){
			memo[i] = sum;
			sum += a[i];
		}
		ll Max = -INF;
		rep(i, n - k + 1){
			sum = memo[i + k] - memo[i];
			Max = max(Max, sum);
		}
		printf("%lld\n", Max);
	}
	return 0;
}

C++: #include<cstdio>
#include<string>
#include<vector>
#include<sstream>
#include<deque>
#include<algorithm>
#include<queue>

using namespace std;

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

int ini[100001];
int main(){
	while(1){
		int n,m;
		scanf("%d%d",&n,&m);
		if(n==0)break;
		rep(i,n){
			scanf("%d",&ini[i]);
		}
		
		int sum=0;
		rep(i,m){
			sum+=ini[i];
		}
		
		int maxi=sum;
		for(int i=m;i<n;i++){
			sum-=ini[i-m];
			sum+=ini[i];
			maxi=max(maxi,sum);
		}
		
		printf("%d\n",maxi);
	}
}

C++: #include<iostream>
#define MIN -1000000000000000000
using namespace std;

int input[100010];

int main() {
	int N,K;
	long long int sum=0,nummax=MIN;
	cin >> N >> K;

	for(int i=0;i<N;i++){
		cin >> input[i];
		sum+=input[i];
		if(i+1>=K){
			sum-=input[i-K];
			if(nummax<sum)nummax=sum;
			cout<< "   " << sum << "   "<< nummax <<endl;
		}
	}
	cout << nummax <<endl;

	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
	while(1){
		int n, k, ans = -1000000, sum = 0;
		cin >> n >> k;
		if (n == 0 && k == 0){
			return 0;
		}
		int yj[200008] = {};
			for(int i = 0; i < n; i++){
				cin >> yj[i];
			}
		for(int i = 0; i < k; i++){
			sum += yj[i];
		}
		for(int i = 0; i < n - k; i++){
			sum += yj[i+k];
			sum -= yj[i];
			ans = max(sum, ans);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, k;
	while (scanf("%d%d", &n, &k), n|k)
	{
		int a[100000];
		for (int i = 0; i < n; ++i)
			scanf("%d", a + i);
		int res, sum;
		res = sum = accumulate(a, a+k, 0);
		for (int i = k; i < n; ++i)
		{
			sum += a[i] - a[i-k];
			res = max(res, sum);
		}
		printf("%d\n", res);
	}
}