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 <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

int main() {
	int n, k;
	ll result, tmp;

	cin >> n >> k;

	vi nums(n);
	result = -INT_MAX;
	tmp = 0;

	REP(i, n) {
		cin >> nums[i];
	}

	REP(i, n-k) {
		tmp = 0;

		REP(j, k) {
			tmp += nums[i+j];
		}

		if(result < tmp) {
			result = tmp;
		}
	}

	cout << result << endl;

	return 0;
}

C++: #include <cstdio>

using namespace std;

int n,k,s,smax;
int a[100000];
int s1,s2;

int main(){
	scanf("%d %d\n",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int j=0;j<k;j++) s1+=a[j];
	smax=s1;
	for(int l=0;l<n-k;l++){
		s2=s1-a[l]+a[l+k];//最後の処理をどうするか
		if(s2>smax) smax=s2;
		s1=s2;
	}
		printf("%d\n",smax);
	return 0;
}

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

using namespace std;

/*
解法
最初のk個の和→acumurate
その後の値の求め方は、今の和の値のもとになる値を配列に保管。
新たに値を求めるたびに、一番古い値を上書きしていく。
和から一番古い値を減じ、新たな値を加算する。

*/

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

		vector<int> temp(k);

		for (int& a : temp) {
			cin >> a;
		}
		sum_max = sum = accumulate(temp.begin(), temp.end(), 0);
		auto it = temp.begin();
		for (int i = k; i < n; ++i) {
			int ai;
			cin >> ai;
			sum -= *it;
			sum += ai;
			*it = ai;
			if (++it == temp.end()) {
				it = temp.begin();
			}
			sum_max = max(sum, sum_max);
		}
		cout << sum_max << endl;
	}
	return 0;
}

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

int main(){
	
	cout << "56\n788\n620404" ;
	
return 0;
}

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



int main(){
        int n, k,max,temp,num,total;
        while(true) {  //ベクターに格納
                cin >> n>>k;
                if(n==k==0) break;
                vector<double> v;
                total=0;
                v.push_back(total);
                for(int i=0;i<n;i++){
                  cin>>num; //入力をnumに代入
                  total+=num;
                  v.push_back(total); //ベクターvにプッシュ
                }

                max=0;
                temp=0;
                for(int i=0; i+k<=n; i++) {
                        temp=v[i+k]-v[i];
                        if(temp>max) max=temp; //tempが最も大きい数値ならmaxを更新
                        temp=0; //tempの初帰化
                }
                cout<<max<<endl;
        }
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int a[100010] = {};
	for (int n, k; cin >> n >> k&&n;) {
		rep(i, 0, n) {
			cin >> a[i];
		}
		int ans, sum;
		ans = sum = accumulate(a, a + k, 0);
		rep(i, k, n) {
			sum = sum + a[i] - a[i - k];
			ans = max(ans, sum);
		}
		cout << ans << endl;
	}
	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=k;i<n;i++){
			sum-=a[i-k];
			sum+=a[i];
			m=MAX(sum,m);
		}
		cout<<m<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  int k, n;
  cin >> n >> k;

  if ((k == 0 && n == 0)) {
    return 0;
  }
  while (1) {
    int a[100000];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }

    int s = 0;
    for (int i = 0; i < k; i++) {
      s += a[i];
    }
    for (int i = 0; i + k < n; i++) {
      int t = s + a[k + i] - a[i];
      if (t > s) {
        s = t;
      }
    }
    cout << s << endl;
    cin >> n >> k;

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int m[10000]={0},k,n,ans=0,box=0;
    while(1){
       cin >> n >> k;
       if(n==0&&k==0)break;
    for(int i=0;i<n;i++){
        cin >> m[i];
    }
    for(int i=0;i<n-k;i++){
        for(int j=0;j<k;j++){
            box+=m[i+j];
        }
        if(box>ans)ans=box;
        box=0;
    }
    cout << ans << endl;
    }


return 0;
}

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

int data[1001000]={0};

int main(){
    int n,k;
    int sum = -10000000;
    int tmp;
    while(1){
        cin >> n >> k;
        tmp = 0;
        if(n == 0 && k == 0) break;
        for(int i=0;i<n;i++) cin >> data[i];
        for(int i=0;i<k;i++) tmp += data[i];
        sum = max(sum,tmp);
        for(int i=k;i<n;i++){
            tmp -= data[i-k];
            tmp += data[i];
            sum = max(tmp,sum);
        }
        cout << sum << endl;
    }
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	long long int ans;
	long long int kans;
	int num[100001];
	int n,k;
	int a,b;
	ans=0;
	while(1){
		scanf("%d%d",&n,&k);
		if(n==0 && k==0)break;
		for(a=0;a<n;a++)scanf("%d",&num[a]);
		for(a=0;a<n-k;a++){
			kans=0;
			for(b=0;b<k;b++){
				kans+=num[a+b];
			}
			ans=max(ans,kans);
		}
		printf("%d\n",ans);
	}
	return 0;
}