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 <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(){
    ll n,k;
    while(cin>>n>>k,n+k){
    vl dp;
    vl sum(n,0);
    rep(i,n){
        ll ujimatu; cin>>ujimatu;
        dp.push_back(ujimatu);
        if(!i)sum[i]=ujimatu;
        else if(i<k)sum[i]=sum[i-1]+ujimatu;
        else sum[i]=ujimatu+sum[i-1]-dp[i-k];
        
    }
    ll ans=-INF*INF;
    rep(i,n)if(i>=k-1)cmax(ans,sum[i]);
    ///ep(i,n)if(i>=k-1)cout<<sum[i]<<endl;
    cout<<ans<<endl;
    }
}

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

using namespace std;

int main(){
	int n,k,sum,max;
	int a[100001];
	while(scanf("%d %d",&n,&k)){
		if(n==0&&k==0)
		break;
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		sum=0;
		max=0;
		for(int i=0;i<n;i++){
			if(i<k)
			sum+=a[i];
			else if(i>=k){
				sum+=a[i];
				sum-=a[i-k];
			}
			if(i==k-1)
			max=sum;
			else if(i>k-1){
				max=(max<sum ? sum:max);
			}
		}
		printf("%d\n",max);
	}
}

C++: #include <cstdio>
#include <vector>
using namespace std;
#define MAX_N 100000

int main(){
	int n, k;
	scanf("%d %d", &n,&k);
	vector<int> data(MAX_N);
	for( int i=0; i<n; i++ ){
		scanf("%d", &data[i]);
	}
	int ans = 0;
	for( int i=0; i<n-k; i++ ){
		int sum = 0;
		for( int j=0; j<k; j++ ) sum += data[i+j];
		ans = max(ans, sum);
	}
	printf("%d\n", ans);
}

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

int N = 1 << 17;
int seg[N * 2];

void update(int x, int v) {
    x += N - 1;
    seg[x] = v;
    while (x) {
        x = (x - 1) / 2;
        seg[x] = seg[x + x + 1] + seg[x + x + 2];
    }
}
int query(int a, int b, int x, int l, int r) {
    if (b <= l || r <= a) return 0;
    if (l <= a && b <= r) return seg[x];
    return query(a, b, x + x + 1, l, (l + r) / 2) + query(a, b, x + x + 2, (l + r) / 2, r);
}
int Q(int a, int b) { return query(a, b, 0, 0, N); }

int in() { int x; scanf("%d", &x); return x;}

int main(void)
{
    int n = in(), K = in();
    for (int i = 0; i < n; i++) update(i, in());
    int mini = 1 << 30;
    for (int i = 0; i < n - K; i++) mini = min(mini, Q(i, i + K));
    cout << mini << endl;
    return 0;
}

C++: #include <iostream>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
	int *a, *a2, m, n, t1, t2;
	
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		
		a = (int *)calloc(n-m+1, sizeof(int));
		a2 = (int *)calloc(n, sizeof(int));
		
		for(int i = 0; i < n; i++){
			cin >> t1;
			a2[i] = t1;
		}
		
		for(int i = 0; i < m; i++){
			a[0] += a2[i];
		}
		
		for(int i = 0; i < n-m; i++){
			a[i+1] += (a2[m+i] + a[i] - a2[i]);
		}
		
		sort(a, a+(n-m+1));
		
		cout << a[n-m] << endl;
		
		free(a2);
		free(a);
	}
	
	return 0;
}

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

C++: #include <cstdio>
#include <vector>

using namespace std;

int n,k;
vector<int> v;

int main(){
	int a;
	int i;
	while(scanf("%d %d",&n,&k) && (n || k) ){
		v.clear();
		for(i=0;i<n;i++){
			scanf("%d",&a);
			v.push_back(a);
		}
		a = 0;
		for(i=0;i<k;i++){
			a+=v[i];
		}
		//printf("%d-%d,%d\n",i-k,i,a);
		int max = a;
		for(;i<n;i++){
			a = a - v[i - k] + v[i];
			//printf("%d-%d,%d\n",i-k,i,a);
			if(max < a){max = a;}
		}
		printf("%d\n",max);
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>

using namespace std;

int a[100000];

int main() {
	int n, k;
	
	while (cin >> n >> k && n != 0) {
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		int sum = 0, ans = 1 << 31;
		for (int l = 0, r = 0; r < n; ++r) {
			if (r - l == k) {
				ans = max(ans, sum);
				sum -= a[l++];
			}
			sum += a[r];
		}
		cout << ans << endl;
	}

	return 0;
}

C++: #include <stdio.h>
int main(){
    long long int n,k,a[1000000],top;
    while(1){
        scanf("%lld%lld",&n,&k);
        if(n==0)return 0;
        scanf("%lld",&a[0]);
        for(int i=1;i<k;i++){
            scanf("%lld",&a[i]);
            a[i]+=a[i-1];
        }
        top=a[k-1];
        for(int i=k;i<n;i++){
            scanf("%lld",&a[i]);
            a[i]+=a[i-1];
            a[i]-=a[i-k];
            if(a[i]>top)top=a[i];
        }
        printf("%lld\n",top);
    }
}

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

using namespace std;

int main() {
  for (;;) {
    int n, k;
    cin >> n >> k;
    if (!n && !k) return 0;
    int a[n];
    long long result = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i < k)
        result += a[i];
    }
    long long sum = result;
    for (int i = k; i < n; i++) {
      sum = sum - a[i-k] + a[i];
      result = max(result, sum);
    }
    cout << result << endl;
  }
}

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

int main(){
  int i,j,n,k,a[100000],s,max;
  while(1){
    cin >> n >> k;
    if(n == 0 && k == 0) break;
    max = 0;

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

    for(i=0;i<n;i++){
      s = a[i];
      for(j=1;j<k;j++){
	if(i + j >= n) break;
	s += a[i+j];
      }
      if(max < s && j == k){
	max = s;
      }
    }

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

C++: #include <cstdio>

int main() {
    long n, k;
    for (;;) {
        long a[100002] = {};
        scanf("%ld %ld", &n, &k);
        if (n == 0)
            return 0;
        for (long i = 0; i < n; i++) {
            scanf(" %ld", &a[i]);
        }
        long max = 0;
        for (long i = 0; i < n - k; i++) {
            long result = a[i] + a[i+1] + a[i+2];
            if (result > max)
                max = result;
        }
        printf("%ld\n", max);
    }
}

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

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

  }
  return 0;
}