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 <iostream>
using namespace std;

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

    int* num_sequence = new int[n];
    for (int i = 0; i < n; i++)
    {
      cin >> num_sequence[i];
      //cout << i << ':' << num_sequence[i] << endl;
    }

    max = -999999;
    for (int j = 0; j < n-k+1; j++)
    {
      sum = 0;
      for (int i = 0; i < k; i++)
      {
        sum += num_sequence[i+j];
      }
      if ( sum > max ) max = sum;
    }

    cout << max << endl;

    delete[] num_sequence;
  }
  return 0;
}

C++: #include<fstream>
using namespace std;
int main(){
ifstream fin("input.txt");
ofstream fout("output.txt");
long long n,k,i,a[100000],s[100000],x;
while(fin>>n>>k,n*n+k*k){
for(i=0;i<n;i++)fin>>a[i];
for(s[0]=i=0;i<k;i++)s[0]+=a[i];
for(i=1;i<n-k+1;i++)s[i]=s[i-1]-a[i-1]+a[i+k-1];
x=-1000000000;
for(i=0;i<n-k+1;i++)if(x<s[i])x=s[i];
fout<<x<<endl;
}
return 0;
}

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

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

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n,k;
	while(1){
		cin>>n>>k;
		if(n+k==0) break;
		vi a(n);
		rep(i,0,n) cin>>a[i];
		int sum=0;
		rep(i,0,k) sum+=a[i];
		int MAX=sum;
		rep(i,k,n){
			sum=sum+a[i]-a[i-k];
			MAX=max(MAX,sum);
		}
		o(MAX);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
bool solve(){
    int arr[100001]={0};
    int N,K;
    scanf("%d%d",&N,&K);
    if(N==0&&K==0)return false;
    for(int i=0;i<N;i++){
        scanf("%d",&arr[i+1]);
        arr[i+1]+=arr[i];
    }
    int ma=INT_MIN;
    for(int i=0;i+K<=N;i++){
        ma=max(ma,arr[i+K]-arr[i]);
    }
    printf("%d\n",ma);
    return true;
}

int main(){
    while(solve());
}

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

using namespace std ;

int main()
{
	int n ;
	while( cin >> n ,n )
	{
		int m ;
		cin >> m ;
		int num[ n ] ;
		for( int i  = 0 ; i < n ; i++ )
			cin >> num[ i ] ;
		int ans = 0 ;
		for( int i  = 0 ; i < n ; i++ )
		{
			int cnt = 0 ;
			for( int j = i ; j < m + i && m + i < n ; j++ )
				cnt += num[ j ] ;
			ans = max( ans ,cnt ) ;
		}
		cout << ans << 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[100000] = {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<iostream>
using namespace std;

long long int num[100100];


int main(){
    long long int n,m;
    long long int sum=0;
    long long int ans=0;
    while(1){
        cin>>n>>m;
        if(n==0&&m==0)break;
        for(int i=0;i<100100;i++){
            num[i]=0;
            if(num[i+1]==0)break;
        }
        for(int i=0;i<n;i++){
            cin>>num[i];
            if(i<m)sum+=num[i];
        }
        for(int i=1;i<n;i++){
            sum=sum-num[i-1]+num[i];
            if(ans<sum)ans=sum;
        }
        if(ans>=0)cout<<ans<<endl;
        else cout<<0<<endl;
        ans=0;
        sum=0;
        }
    return 0;
}

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

unsigned long long int n, k, i, j, a[MAX_N], max = 0, f;

int sort(const void *a, const void *b){
  return *(int*)b - *(int*)a;
}

int main(){
  while(1){
    scanf("%lld %lld", &n, &k);
    if(n == 0 && k == 0) break;
    max = 0;
    for(i = 0; i < n; i++) scanf("%lld", &a[i]);
    for(i = 0; i < k; i++) max += a[i];
    f = max;
    for(i = 0; i <= n - k; i++){
      f -= a[i];
      f += a[i + k];
      if(f > max) max = f;
    }
    printf("%lld\n", max);
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int n, k;
int a[1000000];
int s, t;
int main()
{
	cin >> n >> k;
	while(n*k!=0)
	{
		s=0;
		for(int i=0; i<k; i++)
		{
			cin >> a[i];
			s+=a[i];
			t=s;
		}
		for(int i=k; i<n; i++)
		{
			cin >> a[i];
			t=t+a[i]-a[i-k];
			s=max(s, t);
		}
		cout << s << endl;
		cin >> n >> k;
	}
	return 0;
}

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