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<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,result = -100000;
    int num[100005] = {0};
    int memo[100000] = {0};
    while(cin >> n >> m,n + m)
    {
        for(int i = 0; i < n; i++)cin >> num[i];
        for(int i = m-1; i < n; i++)
        {
            memo[i]=0;
            if(i == m-1)
            {
                for(int j = 0; j < m; j++)
                {
                    memo[i] += num[i-j];
                }
            }
            else if(i > m-1)
            {
                memo[i] = memo[i-1] +  num[i] - num[i-m];
            }
        }
        for(int i = m - 1; i < n; i++)
        {
            result = max(result,memo[i]);
        }
        cout << result << endl;
        result = -100005;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int n,k,a,max;
  int set[100001];
  while(1){
    scanf("%d %d",&n,&k);
  if(n==0 && k==0)break;
  max=0;
  for(int i=0;i<n;i++){
    scanf("%d",&set[i]);
  }
  for(int i=0,sum=0;i<n-k+1;i++,sum=0){
    if(set[i-1]<set[i+k-1] || i==0){
      for(int j=i,l=i+k-1;;j++,l--){
	sum += set[j]+set[l];
	if(l-j==1){
	  break;
	}else if(l==j){
	  sum-=set[j];
	  break;
	}
      }
    }
    if(max<sum || i==1){
      max=sum;
    }
  }
  printf("%d\n",max);
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
	for (;;)
	{
		int a,b,c,d,max=0;
		cin>>a>>b;
		int e[a];
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			cin>>d;
			e[c]=d;
		}
		for (int f=0;f<=a-b;f++){
			for (int g=1;g<b;g++){
				e[f]=e[f]+e[f+g];
			}
			if (e[f]>=max) max=e[f];
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>

#define MAX_BIT_SIZE 100001

int BIT[MAX_BIT_SIZE];
int n;
int save[MAX_BIT_SIZE];

int sum(int index) {
    int ret = 0;
    index += 1;

    while (index > 0) {
        ret += BIT[index];
        index -= (index & (-index));
    }

    return ret;
}

void add(int index, int value) {
    int i = 1;
    index += 1;

    while (index <= n) {
        BIT[index] += value;
        index += (index & (-index));
    }
}

int main() {
    while (1) {
        int k;
        int i;
        int max_count = 0;

        scanf("%d %d", &n, &k);
        if (n == 0 && k == 0) return 0;

        memset(BIT, 0, MAX_BIT_SIZE);

        for (i=0;i<n;i++) {
            int d;
            scanf("%d", &d);
            save[i] = d;
            add(i, d);
        }

        for (i=0;i<n-k;i++) {
            int now_count = sum(i+k) - sum(i);
            if (now_count > max_count){
                max_count = now_count;
            }
        }

        printf("%d\n", max_count);
    }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
	for (;;)
	{
		int a,b,c,d,max=0;
		cin>>a>>b;
		int e[a];
		if (a==0&&b==0) break;
		for (c=0;c<a;c++){
			cin>>d;
			e[c]=d;
		}
		for (int f=0;f<=a-b;f++){
			for (int g=1;g<b;g++){
				e[f]=e[f]+e[f+g];
			}
			if (e[f]>=max) max=e[f];
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int N,M;
        int lis[100002];
        cin>>N>>M;
        if(N==0&&M==0)break;
        for(int i=0;i<N;i++)cin>>lis[i];
        int now=0,ans=0;
        for(int i=0;i<M;i++)now+=lis[i],ans+=lis[i];
        for(int i=1;i+M<=N;i++)now=now-lis[i-1]+lis[i+M-1],ans=max(now,ans);
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

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

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=-2000000000;
		for(int i=0;i<time;++i){
			cin>>dommy;
			nownum-=num[i%siz];
			nownum+=dommy;
			num[i%siz]=dommy;
			if(max<nownum&&i+1>=siz){
				max=nownum;
			}
		}
		cout<<max<<endl;
		delete num;
	}
	return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n,k;
    while(cin>>n>>k,n+k){
    vl dp(n,0);
    rep(i,n){
        ll ujimatu; cin>>ujimatu;
        if(!i)dp[0]=ujimatu;
        else if(i<k)dp[i]=ujimatu+dp[i-1];
        else dp[i]=dp[i-1]+ujimatu-dp[i-k];
    }
    ll ans=-INF*INF;
    rep(i,n)cmax(ans,dp[i]);
    cout<<ans<<endl;
    }
}