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++: while 1:
    n,k = [int(i) for i in input().split()]
    if not n and k:
        break
    a = [int(input()) for i in range(n)]
    b = [0]*len(a)

    for i in range(n):
        b[i] = b[i-1] + a[i]
    b = b + [0]

    c = [b[i + k - 1] - b[i - 1] for i in range(n - k + 1)]

    print(max(c))

C++: #include<iostream>
using namespace std;
int main()
{
    int n,k,x;
    cin >> n >> k;
    while(n!=0||k!=0){
       vector<int> a(n);
        cin >> a;
        S[0]=0;
        for(int i=1;i<n;i++){
            S[i]=S[i-1]+a.at(i-1);
        }
        x=S[k];
        for(int l=1;l<n-k;l++){
            if(x<S[k+l]-S[l]){
                x=S[k+l]-S[l];
            }
        }
        cout << x << endl;
        cin >> n >> k;
        

    }

}

C++: //include----------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << "\n";
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos( -1.0 );

//global-----------------------------------------------------------------------------------------------------------------------
int n, m, k;
VI a, b, c;
#define mod 1000000007
//function-------------------------------------------------------------------------------------------------------------------- 
int main() {
	while ( true ) {
		scanf( "%d %d", &n, &m );
		if ( !n && !m ) {
			return 0;
		}
		rep( i, n ) {
			scanf( "%d", &k );
			a.push_back( k );
		}
		int mx = 0;
		rep( i, n - m + 1 ) {
			int d = 0;
			rep( j, m ) {
				d += a[ i + j ];
			}
			mx = max( mx, d );
		}
		printf( "%d\n", mx );
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int n, k, a[112345];
int ans;

int main()
{
	while (true)
	{
		memset(a, 0, sizeof(a));
		ans = -1;
		in >> n >> k;
		rep(i, n) { in >> a[i + 1]; }
		if (n == 0 && k == 0) { break; }

		rep(i, n) { a[i + 1] += a[i]; }
		rep(i, n - k + 1)
		{
			auto res = a[i + k] - a[i];
			ans = std::max(ans, res);
		}

		out << ans << std::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\n" ;
	
return 0;
}

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

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

int main()
{
	while (1)
	{
		int a = 0, b = 0;
		double c = -1000;
		double as = 0;
		cin >> a;
		cin >> b;
		if (a == 0 && b == 0)
		{
			break;
		}
		vector<double> size;
		for (int i = 0; i < a; i++)
		{
			int w;
			cin >> w;
			size.push_back(w);
		}
		for (int i = 0; i < a - 2; i++)
		{
			
			for (int ii = 0; ii < b; ii++)
			{
				as += size[i + ii];
			}
			size.push_back(as);
		}
		for (int i = 0; i < a - 2; i++)
		{
			if (c < size[i + a])
			{
				c = size[i + a];
			}
		}
		cout << c << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k;
    long long int a;
    const long long int INF=1LL<<60;
    while (cin>>n>>k) {
        if (n==0&&k==0) {
            break;
        } else {
            std::deque<long long int> deq;
            for (int i=0;i<n;i++) {
                cin>>a;
                deq.emplace_back(a);
            }
            std::deque<long long int> s(n+1,0);
            long long int ans=-INF;
            for (int i=0;i<n;i++) {
                s[i+1]=s[i]+deq[i];
            }
            for (int i=0;i<=n-k;i++) {
                ans=max(ans,s[k+i]-s[i]);
            }
            cout<<ans<<endl;
        }
    }
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
	int n,k;
	while(1){
		scanf("%d %d",&n,&k);
		if(n==0)	return 0;
		int a[n];
		for(int i=0;i<n;i++)	scanf("%d",&a[i]);
		ll bgs=0,temp=0;
		for(int i=0;i<k;i++)	temp+=a[i];
		bgs=temp;
		for(int i=1;i<=n-k;i++){
			temp=temp-a[i-1]+a[i+k-1];
			bgs=max(bgs,temp);
		}
		printf("%lld\n",bgs);
	}
}

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

C++: #include <iostream>
using namespace std;
int main() {
	int n, k, a[100005] = { 0 }, sum[100005] = { 0 }, m = -299999;
	cin >> n >> k;
	if (n == 0 && k == 0) return 0;
	for (int i = 0; i < n; i++) cin >> a[i];
	sum[0] = a[0] + a[1] + a[2];
	for (int i = 1; i < n-2; i++) {
		sum[i] = sum[i - 1] + a[i + 2] - a[i - 1];
	}
	for (int i = 0; i < n - 2; i++) {
		if (m < sum[i]) {
			m = sum[i];
		}
	}
	cout << m << endl;
}