Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	for true {
		n, k := scanInt(sc), scanInt(sc)
		if n == 0 && k == 0 {
			break
		}
		sum := make([]int, n+2)
		for i := 2; i <= n+1; i++ {
			sum[i] = sum[i-1] + scanInt(sc)
		}
		max := math.MinInt32
		for i := 1; i+k <= n+1; i++ {
			if v := sum[i+k] - sum[i]; max < v {
				max = v
			}
		}
		fmt.Println(max)
	}
	return
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <cstdio>
#include <algorithm>
#define MAX 100000
using namespace std;

int main(){
	int n, m;
	while(scanf("%d %d", &n, &m)){
		if(n == 0 and m == 0) break;
		int array[MAX];
		fill(array, array + MAX, 0);
		for(int i = 0; i < n; i++) scanf("%d", &array[i]);
		
		int sum = 0, max = 0;
		for(int i = 0; i < n - m; i++){
			sum = 0;
			for(int j = i; j < i + m; j++){
				sum += array[j];
			}
			max = sum > max ? sum : max;
		}
		printf("%d\n", max);
	}
	return 0;
}

C++: #include <iostream>
#define MAX(a,b) (((a)>(b))?(a):(b))
using namespace std;

int main(void){
	int n,k;
	while (cin>>n>>k,n||k) {
		int a[100000];
		int sum=0;
		int m=0;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<k;i++)sum+=a[i];
		m=sum;
		for(int i=0;i<=n-k;i++){
			sum-=a[i+k-1];
			sum+=a[i];
			m=MAX(sum,m);
		}
		cout<<m<<endl;
	}
	return 0;
}

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

C++: #include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

using namespace std;
typedef long long ll;

ll sum[100010];
ll a[100010];

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

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

		sum[1] = a[1];
		for (int i = 2; i <= n; i++) {
			sum[i] = sum[i - 1] + a[i];
		}

		ll mx = 0;
		ll ans = 0;
		for (int i = k; i <= n; i++) {
			mx = sum[i] - sum[i - k];
			ans = max(mx, ans);
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

ll solve(int n, int k) {
    ll a[n+1];
    a[0] = 0LL;
    for(int i=1;i<=n;++i){
        cin >> a[i];
        a[i] += a[i-1];
    }

    ll ans = -(1LL << 60);
    for(int i=1;i<=n-k;++i) {
        ans = max(ans, a[i+k-1]-a[i-1]);
    }
    return ans;
}

int main() {
    int n, k;

    while(cin >> n >> k && n) {
        cout << solve(n, k) << endl;
    }
}

C++: #include <iostream>

using namespace std;

#define NMAX 5000

int n, k;
int a[NMAX];

int solve() {
    int max_sum = -10000000;
    int sum = 0;
    for (int i = 0; i + k < n; i++) {
        for (int j = i; j < i + k; j++) {
            sum += a[j];
        }
        if (sum > max_sum) max_sum = sum;
        sum = 0;
    }
    return max_sum;
}

int main() {
    while (true) {
        cin >> n >> k;
        if (n == 0 && k == 0) break;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        cout << solve() << endl;
    }
    return 0;
}

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], result = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i < k)
        result += a[i];
    }
    cout << result << endl;
    for (int i = k; i < n; i++)
      result = max(result, result - a[i-k] + a[i]);
    cout << result << endl;
  }
}

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;
    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+1-k; ++q){
      s = q;
      ans_t = 0;

      for(;s<k+q;++s){
	ans_t += a_n[s];
      } 

      if(q == 0){
        ans = ans_t;
      }
      else{
        if(ans_t > ans){
          ans = ans_t;
        }
      }
    }
    cout<<ans<<endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = (1 << 29);

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

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

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

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

bool has_key_using_count(map<char, char> &m, char n){
    if (m.count(n) == 0){
		//cout << "m doesn't have " << n << "." << endl;
        return false;
    }
    else{
        //cout << "m has " << n << "." << endl;
        return true;
    }
}

int main()
{
	//ifstream cin("sample.txt");

	int n = 0, k = 0, max = 0, tmp = 0, sumTmp = 0;
	
	vector<int> series, seriesK, sum;

	series.clear();
	seriesK.clear();
	sum.clear();
	// 読み込み
	cin >> n >> k;
	rep(i, n) {
		cin >> tmp;
		series.push_back(tmp);
	}

	// 複数のseriesKの最大値を求める
	for (int i = 1; i < n-k+1; i++) {
		seriesK.clear();
		sumTmp = 0;

		// Kまでの数列作成
		for (int j = i; j < i+k; j++) {
			seriesK.push_back(series[j]);
			sumTmp += series[j];
		}

		// 和を求めて格納
		sum.push_back(sumTmp);
	}

	// 和の中で最大のものを出力
	rep(i, sum.size()) {
		if (sum[i] > max) {
			max = sum[i];
		}
	}

	// 出力する
	cout << max << endl;

	return 0;
}

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

using namespace std;

int main(void) {
	int n, k, in, sum, res;
	vector<int> val;
	int i, j;

	while(true) {
		cin >> n >> k;
		if((n == 0 && k == 0) || cin.eof()) { break; }
		val.clear();
		res = 0;
		for(i = 0; i < k; i++) {
			cin >> in;
			val.push_back(in);
		}
		sum = 0;
		for(i = 0;i < k; i++) {
			sum += val[i];
		}
		res = max(res, sum);
		for(i = k; i < n; i++) {
			val.erase(val.begin());
			cin >> in;
			val.push_back(in);
			sum = 0;
			for(j = 0;j < k; j++) {
				sum += val[j];
			}
			res = max(res, sum);
		}
		cout << res << endl;
	}

	return 0;
}