Go: package main

import "fmt"

func main() {

	for true {
		var n, k int
		fmt.Scan(&n, &k)

		if n == 0 && k == 0 {
			return
		}
		
		a := make([]int, n)
		ans := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if i == 0 {
				ans[i] = a[i]
			} else {
				ans[i] = ans[i-1] + a[i]
			}
		}
		max := 0
		for i := k; i < n; i++ {
			t := ans[i] - ans[i-k]
			if max < t {
				max = t
			}
		}
		fmt.Println(max)
	}
}

C++: #line 1 "cumulative_sum.test.cpp"
#define  PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0516"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

#line 1 "../cumulative_sum.cpp"
template<class T>
struct CumulativeSum {
  vector<T> v;

  CumulativeSum(size_t n) : v(n+1) {};
  CumulativeSum(vector<T> v_) {
    v.resize(v_.size()+1);
    for (size_t i = 0; i < v_.size(); i++) v[i+1] = v_[i];
  };

  void add(size_t i, T x) {
    v[i+1] += x;
  }

  // O(N)
  void build() {
    for (size_t i = 0; i < v.size()-1; i++)
      v[i+1] += v[i];
  }

  // O(1) sum [l, r]
  T sum(size_t l, size_t r) const {
    return l == 0 ? v[r+1] : v[r+1]-v[l];
  }

  // O(1) sum [0, r]
  T sum(size_t r) const {
    return v[r+1];
  }

  T& operator[](size_t i) {
    return v[i];
  }

  const T& operator[](size_t i) const {
    return v[i];
  }
};
#line 15 "cumulative_sum.test.cpp"

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

  while (1) {
    ll n, k;
    cin >> n >> k;
    if (n == 0 and k == 0) return 0;
    vl a(n);
    rep(i, n) {
      cin >> a[i];
    }

    CumulativeSum<ll> cs(a);
    cs.build();
    ll ans = -1e4;
    for (ll i = 0; i+k-1 < n; i++) {
      cmax(ans, cs.sum(i, i+k-1));
    }

    cout << ans << endl;
  }
}

C++: #include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int n, k;
int a[100000];
int s, m;

int main(void) {
  while(cin >> n >> k, !(n == 0 && k == 0)) {
    REP(i, 0, n) {
      cin >> a[i];
    }

    s = 0;
    REP(i, 0, k) {
      s += a[i];
    }

    m = s;
    REP(i, k, n) {
      s += a[i] - a[i - k];
      if(s > m) m = s;
    }

    cout << m << endl;
  }

  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,k;
	while(1){
		int a[100000];
		cin>>n>>k;
		if(n==0&&k==0)break;
		int max=0,sum;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int i=0;i<n;i++){
			sum=0;
			if(i+k-1<n){
				for(int j=0;j<k;j++){
					sum+=a[i+j];
				}
				if(max<sum){
					max=sum;
				}
			}
			else break;
		}
		cout<<max<<endl;
	}
}

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;

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

      sum_seq=0;

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

      if(max<sum_seq) max=sum_seq;

    }

    cout << max << endl;

  }

  return 0;

}

C++: #include <stdio.h>
int n,k,x[100005],cur,ret;
int main(){
for(;;){
	ret=-2000000000;cur=0;
	scanf("%d%d",&n,&k);if(!n)return 0;
	for(int i=0;i<n;i++){
		scanf("%d",&x[i]);
		cur+=x[i];
		if(i>=k) cur-=x[i-k];
		if(i>=k-1&&ret<cur) ret=cur;
	}
	printf("%d\n",ret);
}
}

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;
    int total = 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++: // This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

int main() {
    int n,k;
    cin >> n >> k;
    int max = 0;
    vector<int> a(100005, 0);
    vector<int> s(100005,0);
    while (n != 0 || k != 0) {
        int b;
        s[0] = 0
        for(int i = 0; i < n; i++) {
            cin >> b;
            s[i+1] = s[i] + b;
        }
        for (int j = 0; j < n-k; j++) {
            if(max < s[i+k] - s[i]) {
                max = s[i+k] - s[i];
            }
        }
        cout << max << endl;
        cin >> n >> k;
    }
}

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

int main(){
	int n,k,max,buf,*a;
	
	while(1){
		cin >> n >> k;
		
		if(n || k){
			max = 0;
			
			a = new int[n];
			
			for(int i = 0; i < n; i++){
				cin >> a[i];
			}
			
			for(int i = 0; i <= n-k; i++){
				buf = 0;
				
				for(int j = 0; j < k; j++){
					buf += a[i+j];
				}
				
				if(max < buf){
					max = buf;
				}
			}
			
			cout << max << endl;
		}else{
			break;
		}
	}
	
	return 0;
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int a[100001],m,n;
  int mx;
  a[0]=0;
  while(cin>>n>>m&&n+m){
    for(i=1;i<n+1;i++){
      cin>>a[i];
      a[i]+=a[i-1];
    }
    mx=-1000000000;
    for(i=0;i<n-m+1;i++){
      if(a[i+m]-a[i]>mx)
	mx=a[i+m]-a[i];
    }
    cout<<mx<<endl;
  }
  return 0;
}

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

    }
    return 0;
}

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

using namespace std;

int main(){
	deque<int> deq;
	int n,k,max,buf;
	
	while(1){
		cin >> n >> k;
		
		if(n || k){
			max = 0;
			
			deq.clear();
			deq.push_front(0);
			for(int i = 0; i < k-1; i++){
				cin >> buf;
				deq.push_front(buf);
				n--;
			}
			
			for(; n > 0; n--){
				cin >> buf;
				deq.push_front(buf);
				deq.pop_back();
				
				buf = 0;
				
				for(int i = 0; i < k; i++){
					buf += deq.at(i);
				}
				
				if(max < buf){
					max = buf;
				}
			}
			
			cout << max << endl;
		}else{
			break;
		}
	}
	
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
ll num[100100];
int main()
{
	while(1)
	{
		int n,k;
		cin >> n >> k;
		if(n==0&&k==0)break;
		memset(num,0,sizeof(num));
		for(int i=1;i<=n;i++)
		{
			int p;
			cin >> p;
			num[i]=p;
		}
		for(int i=2;i<=n;i++)
		{
			num[i]+=num[i-1];
		}
		ll ans=-INF;
		for(int i=1;i<=n-k+1;i++)
		{
			ans=max(ans,num[i+k-1]-num[i-1]);
		}
		cout << ans << endl;
	}
	return 0;
}