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;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	vector<int> ans;

	while(true){
		int n, k;
		cin >> n >> k;

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

		vector<int> input;
		rep(i, n){
			int a;
			cin >> a;
			input.push_back(a);
		}

		vector<int> cumu;
		cumu.push_back(0);

		rep(i, n){
			cumu.push_back(cumu[i] + input[i]);
		}

		int sumMax = 0;
		rep(i, n){
			if(n < i + k) break;

			if(sumMax < cumu[i + k] - cumu[i]) sumMax = cumu[i + k] - cumu[i];
		}

		ans.push_back(sumMax);
	}

	rep(i, ans.size()){
		cout << ans[i] << endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int n,a[100001],k,sum,p;
int main(){
int i,j,h;
cin>>n>>k;
cin>>a[1];
for(i=2;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
for(i=1;i<=n;i++){
	for(j=i;i<=i+k;j++){
		p=a[i+k]-a[j];
		if(p>=sum){
			sum=p;
		}
	}
}
cout<<sum<<endl;
return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  bool m = false;
  c = getchar();
  while(!isdigit(c)){
    if(c == '-') m = true;
    c = getchar();
  }
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  if(m) ret = -ret;
  return ret;
}

int main(){
  int n,k;
  while((n = getInt()) + (k = getInt())){
    vector<int> tmp(k);
    int kk = 0;
    int nn = 0;
    int sum = 0;
    int ans = INT_MIN;
    REP(i,n){
      int tt = getInt();
      //cout << "tt=" << tt << endl;
      if(i >= k){
        sum -= tmp[nn++];
        nn %= k;
      }
      tmp[kk++] = tt;
      kk %= k;
      sum += tt;
      if(i >= k - 1){
        ans = max(ans, sum);
      }
    }
    print(ans);
  }
  return 0;
}

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

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 1000000009;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int t, d; };

int main()
{
	int n, k;
	while (cin >> n && n)
	{
		cin >> k;
		vector<LL> sums(n);
		rep(i, n)
		{
			cin >> sums[i];
			if (i != 0)
				sums[i] += sums[i - 1];
		}
		LL ans = sums[k];
		for (int i = 0; i + k < n; i++)
		{
			ans = max(ans, sums[i + k - 1] - sums[i - 1]);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n, k;
	while(cin >> n >> k) {
		if(n == 0 && k == 0) break;

		vector<int> v(n);
		rep(i, n) cin >> v[i];

		int l = v[0], a = 0;
		rep(i, k) a += v[i];

		ll ans = a;
		REP(i, k, n) {
			a -= l;
			a += v[i];

			ans = max(ans, (ll)a);
			l = v[i - k + 1];
		}

		cout << ans << endl;
	}

	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 + 1){
			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<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);
    mx=0;
    }

return 0;
}

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

using namespace std;

int n,k,s,ans,term,ans_t;
vector<int> a_n;
int m,t;

int main()
{

  while(1){
    m = 0;
    ans_t =	0;

    cin>>n>>k;

    if(n == 0 && k == 0){
      break;
    }

    for(int q = 0;q < n;++q){
      cin>>term;
      a_n.push_back(term);
    }

    for(int q =	0;q < n;++q){
      if(q < k){
        ans_t += a_n[q];
        ans = ans_t;
      }
      else{
        m = ans_t	+ a_n[q] - a_n[q-k];
        if(m > ans){
          ans = m;
	}
        ans_t = m;
      }
    }
    cout<<ans<<endl;
  }

  return 0;
}