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++: #include<iostream>
#include<stdlib.h>

using namespace std;

int main(){
  int n,k;
  int sum1=0 , max = 0;
  int now = 0, nextdata, next;
  int* s;
  while(1){
    sum1 = 0;
    max = 0;
    cin >>n >>k;

    if(n == 0) break;

    s = (int*)malloc(sizeof(int) * k);

    int data;
    for(int i = 0; i<k; i++){
      cin >>data;
      s[i] = data;
      sum1 += data;
    }
    max = sum1;
    now = n-1;

    for(int i = 0; i<n-k; i++){
      cin >>data;
      if(now+1 == n) {
	next = 0;
	nextdata = s[0];
      } else{
	next = now + 1;
	nextdata = s[next];
      }

      sum1 = sum1- nextdata + data;
      if( sum1 > max) max = sum1;
      now = next;
      s[now] = data;
    }

    cout << max << endl;
    }
  return 0;
}

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

// #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
// #define FORR(i, a, b) for (int i = (a); i > (b); --i)
// #define REP(i, n) for (int i = 0; i < (n); ++i)
// #define REPR(i, n) for (int i = n; i >= 0; i--)
// #define FOREACH(x, a) for (auto &(x) : (a))
// #define VECCIN(x)            \
// 	for (auto &youso_ : (x)) \
// 	cin >> youso_
// #define mp make_pair
// #define bitcnt __builtin_popcount
// #define All(a) (a).begin(), (a).end()
// template <typename T = long long>
// inline T IN()
// {
// 	T x;
// 	cin >> x;
// 	return (x);
// }
// inline void CIN() {}
// template <class Head, class... Tail>
// inline void CIN(Head &&head, Tail &&... tail)
// {
// 	cin >> head;
// 	CIN(move(tail)...);
// }
// #define CINT(...)    \
// 	int __VA_ARGS__; \
// 	CIN(__VA_ARGS__)
// #define LCIN(...)   \
// 	ll __VA_ARGS__; \
// 	CIN(__VA_ARGS__)
// #define SCIN(...)       \
// 	string __VA_ARGS__; \
// 	CIN(__VA_ARGS__)
// #define Yes(a) cout << (a ? "Yes" : "No") << "\n"
// #define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
// typedef vector<int> V;
// typedef vector<ll> VL;
// typedef pair<int, int> P;
// typedef pair<ll, ll> PL;
// typedef priority_queue<int> PQ;
// typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

vector<int> a;
int n, k;
vector<ll> ret;
int main()
{
	while (true)
	{
		cin >> n >> k;
		if (n == 0 && k == 0)
			break;
		a.resize(n);
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		int l, r;
		l = 0;
		r = 0;
		ll ans = 0, res = 0;
		while (l < n)
		{
			while (r - l < k && r < n)
			{
				ans += a[r++];
			}
			if (l == 0)
				res = ans;
			if (r - l == k)
				res = max(res, ans);
			ans -= a[l++];
		}
		ret.push_back(res);
	}
	for (int i = 0; i < ret.size(); i++)
	{
		cout << ret[i] << "\n";
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

#define MAX 100000
#define INF (10000*100000+1)
int main(){

	 std::ios_base::sync_with_stdio(false);

	int n,k,a[MAX];
	long long num,max;

	while(1){

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

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

		max=-1*INF;
		for(int i=0;i<=n-k;i++){
			num=0;
			for(int j=0;j<k;j++){
				num+=a[i+j];
			}
			max=(max<num)?num:max;
		}
		cout<<max<<endl;
		
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
#define debug(x) cout << #x << " = " << x << endl;
#define sq(x) ((x)*(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

int main(){
	int n, k;
	cin >> n >> k;
	queue<int> q;
	int sum = 0;
	int ans = -1e10;
	rep(i, n){
		int a;
		cin >> a;
		sum += a;
		q.push(a);
		if(q.size() >= k){
			ans = max(ans, sum);
			sum -= q.front();
			q.pop();
		}
	}
	cout << ans << endl;
}

C++: #include<stdio.h>

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

int n,k;
int aa[111111];

void getinput(){
	scanf("%d%d",&n,&k);
	rep(i,n)scanf("%d",&aa[i]);
}


int getfirstsum(int left,int right){
	if(left==right)return aa[left];
	return getfirstsum(left,(left+right)/2) +
			 getfirstsum((left+right)/2+1,right);
}

int main(void){
	
	getinput();
	
	int a = getfirstsum(0,k-1);
	int ans=a;
	rep(i,n-k){
		a = a-aa[i]+aa[i+k];
		if(ans<a){
			ans=a;
		}
	}
	
	printf("%d\n",ans);
}

C++: #include <iostream>
#include <algorithm>
#define N 100000
using namespace std;
int main(){
  int n,k,in[N],maxv,sum,i;
  while(1){
    cin >> n >> k;
    if(n==0&&k==0) break;
    maxv=-2000000;
    sum=0;
    for(i=0;i<n;i++){
      cin >> in[i];
      sum+=in[i];
      if(i>=k){
	sum-=in[i-k];
      }
      if(i>=k-1) maxv=max(maxv,sum);
    }
    cout << maxv << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <array>
#include <set>
#include <string>
#include <numeric>
#include <algorithm>

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



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

    for(;;) {
        int n, k;
        std::cin >> n >> k;
        if (n == 0 && k == 0) break;
        std::vector<int> num(n);
        rep(i, n) std::cin >> num.at(i);

        int sum = std::accumulate(num.begin(),num.begin()+k,0);
        rep(i,n-k) sum = std::max(sum,sum-num.at(i)+num.at(k+i));

        std::cout << sum << "\n";
    }

    return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
	int *num,siz,time,max,nownum;
	while(cin>>time>>siz&&time!=0){
		num=new int[siz];
		for(int i=0;i<siz;++i){
			num[i]=0;
		}
		nownum=0;
		int dommy;
		max=pow((double)2,(double)sizeof(int)*8);
		for(int i=0;i<time;++i){
			cin>>dommy;
			nownum-=num[i%siz];
			nownum+=dommy;
			num[i%siz]=dommy;
			if(max<nownum){
				max=nownum;
			}
		}
		cout<<max<<endl;
		delete num;
	}
	return 0;
}

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

int main(){
	int n, k, num, max, ksum, i;
	while(true){
		cin>>n>>k;if(n==0&&k==0)break;
		queue<int> q;
		max=0;
		for(i=0;i<k;i++){
			cin>>num;
			q.push(num);
			max+=num;
			
		}
		ksum=max;
		for(i=k;i<n;i++){
			cin>>num;
			q.push(num);
			ksum -= q.front();
			q.pop();
			ksum += num;
			if(max<ksum) max = ksum;
		}
		cout<<max<<endl;
	}
	return 0;
}

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

int data[1001000]={0};

int main(){
    int n,k;
    int sum = -1;
    int tmp,tmp2,tmp3,tmp4;
    while(1){
        cin >> n >> k;
        if(n == 0 && k == 0) break;
        for(int i=0;i<n;i++) cin >> data[i];
        for(int i=0;i<=(n-k)/4;i++){
            tmp = 0;
            tmp2 = 0;
            tmp3 = 0;
            tmp4 = 0;
            for(int j=i,g=n-(i+1),f=(n/2)+i,r=(n/2)-i;j<i+k;j++,g--,f++,r--){
                tmp += data[j];
                tmp2 += data[g];
                tmp3 += data[f];
                tmp4 += data[r];
            }
            if(sum < tmp) sum = tmp;
            else if(sum < tmp2) sum = tmp2;
            else if(sum < tmp3) sum = tmp3;
            else if(sum < tmp4) sum = tmp4;
        }
        cout << sum << endl;
    }
}