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<stdio.h>

using namespace std;

int main(){


    int n,k,ans=0,ans2=0,mx=0;
    while(1){
    scanf("%d%d",&n,&k);
    if(n==0&&k==0)break;
    int num[n];
    //for(int y=0;y<n;y++){
      //  scanf("%d",&num[y]);
    //}
        for(int a=0;a<k;a++){
                cin >> num[a];
        ans+=num[a];
        }
        mx=ans;
    for(int j=k;j<n;j++){
            cin >> num[j];
        ans2=ans-num[j-k]+num[j];
        if(mx<=ans2){
            mx=ans2;
        }
    ans=ans2;
    ans2=0;
    }
    printf("%d\n",mx);
    }

return 0;
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

int n, k ,i = 0;
long long int a[100000];
long long int result[100][2];

int main()
{
	for (;; i++)
	{
		cin >> n >> k;
		if (n == 0)
		{
			break;
		}

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

		for (int p = 0; p < n - k; p++)
		{
			for (int q = 0; q < k; q++)
			{
				result[i][0] += a[p + q];
			}
			result[i][1] = max(result[i][0], result[i][1]);
			result[i][0] = 0;
		}
	}
	for (int p = 0; p < i; p++)
	{
		cout << result[i][1] << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int num[100100];
int main(){
int n,m;
int ans=0;
while(1){
         for(int i=0;i<100100;i++)num[i]=0;
         cin>>n>>m;
         if(n==0&&m==0)break;
         for(int i=0;i<n;i++) cin>>num[i];
         for(int i=0;i<n-m;i++){
              int min=0;
              for(int j=i;j<i+m;j++)min+=num[j];
              if(ans<min)ans=min;
         }
         cout<<ans<<endl;
         ans=0;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;
struct Edge { int from, to; long long cost; };
using Graph = vector<vector<Edge>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

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

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

int main () {
    int n, k, a[100000], i, S[100000],m;
    cin >> n >> k;
    for(I=0;i<n;i++) {
        cin >> a[i];
    }
    for(i=0;i<n-k+1) {
        S[i]=S[i-1] - a[i-1] + a[i+k];
        m = max(m,s[i]);
    }
    cout << m << endl;
}

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;
    long long int ans = 0;

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

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

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

#define INT_MIN -2147483648
#define MAX_N 100010
int N, K;
int S[MAX_N];

int main() {
  while (true) {
  cin >> N >> K;
  if (N == 0 && K == 0) break;
  for (int i=0; i<N; i++) cin >> S[i];

  int pre = 0;
  for (int i=0; i<K; i++) pre += S[i];
  int ans = pre;

  for (int i=1; i<=N-K; i++) {
    pre = pre - S[i-1] + S[i+K-1];
    ans = max(ans, pre);
  }
  cout << ans << "\n";
  }
  return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    int n, k, v[100000];
    while (cin >> n >> k, n) {
        int sum = 0, res = -INT_MAX;
        for (int i=0; i<n; ++i) {
            cin >> v[i];
            sum += v[i] - (k <= i ? v[i-k] : 0);
            res = max(res, (k-1 <= i ? sum : -INT_MAX));
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int k,n,a[6000]={0};
    double cube=0,ans=0;
    while(1){
       cin >> n >> k;
       if(n==0&&k==0)break;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n-k;i++){
       cube=0;
       for(int j=0;j<k;j++){
        cube +=a[i+j];
       }
       if(cube>ans)ans=cube;
    }
    cout << ans << endl;
    }
return 0;
}