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++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0516*/
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    while(1){
        int n,k;
        cin >> n >> k;
        if((n==0)&&(k==0)) break;
        int s[n+1];
        s[0]=0;
        rep(i,n){
            int a;
            cin >> a;
            s[i+1]=s[i]+a;
        }
        int res=-1001001001;
        for(int i=0; i+k<n+1; i++){
            int temp=0;
            temp = s[i+k]-s[i];
            if(temp>res) res = temp;
        }

        cout << res << endl;
    }
    return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define SIZE(x) ((int)(x).size())
#define UQ(v) v.erase(unique(v,begin(),v,end()),v.end());
ll INF = 1LL <<30;
#define pb push_back 
int dxy4[5] = { 0,1,0,-1,0 };
int dxy8[9] = { 0,1,1,0,-1,1,-1,-1,0 };
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
ll mod7 = 1000000007;
ll mod9 = 1000000009;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i,x,n) for(int i=x;i<n;++i)
//vector< vector<int> > v (max1, vector<in t>(max2) );

int a[100000];


int main() {
	int n,k;
	while (cin >> n >> k) {
		if (!n)break;
		rep(i, n)cin >> a[i];
		ll sum = 0 ,ans = 0;;
		rep(i, k)sum += a[i];
		FOR(i, k, n) {
			sum = sum + a[i] - a[i - k];
			ans = max(sum, ans);

		}
		cout << ans << endl;
	}
	cin >> n;
	
	return 0;
}

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

C++: #include<iostream>
#include<vector>
using namespace std;
#define MAX 100001
int main(void){
  int n , k;
  while(cin>>n>>k,n+k){
  int in[MAX];
  int dp[MAX];
  for(int i = 0 ; i < n ; i ++) 
    cin>>in[i];
  for(int i = 1 ; i < n ; i ++){
    dp[i] = in[i - 1] + in[i];
  }
  int res = -(1<<22);
  for(int i = 2 ; i < n ; i ++){
    res = max(res,in[i] + dp[i - 1]);
    //cout<<in[i] <<" " << dp[i - 1] << endl;
  }
  
  
  cout<<res<<endl;
  }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 30;
// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int B = 320, MAX_N = 100000;

int A[MAX_N], buckets[MAX_N/B];

int sum(int l, int r){
    int res = 0;
    while(l < r && l % B > 0){res += A[l++];}
    while(l < r && r % B > 0){res += A[--r];}
    while(l < r){
        res += buckets[l/B];
        l += B;
    }

    return res;
}

int main(){
    int N, K;
    while(std::cin >> N >> K, N){
        REP(i, N){
            std::cin >> A[i];
            buckets[i/B] += A[i];
        }

        int res = -INF;
        REP(i, N){
            if(i+K <= N){
                res = std::max(res, sum(i, i+K));
            }
        }

        std::cout << res << std::endl;
    }
}

C++: 

#include <iostream>

using namespace std;

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

    if ((k == 0 && n == 0)) {
      return 0;
    }
    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;
  }
  return 0;
}

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

C++: #include <iostream>
using namespace std;
int main(void){
	for (;;){
	int a,b,c[100000]={0},d=0,e=0,max=0;
			cin>>a>>b;
			if (a==0&&b==0)break;
			for (int A=0;A<a;A++){
			cin>>c[A];
			if (A>=b){
				for (int B=0;B<b;B++){
					d=d+c[A+e];
					e--;
				}
				if (max<d)max=d;
				d=0;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int n, k;
  while(cin >> n >> k, n || k) {
    int a[n]; FOR(i,0,n) cin >> a[i];
    int sum = 0;
    FOR(i,0,k) sum += a[i];
    int mx = sum;
    FOR(i,k,n) {
      sum += a[i];
      sum -= a[i-k];
      mx = max(mx, sum);
    }
    cout << mx << '\n';
  }
  return 0;
}

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

int main() {
	while(true){
		int n=0,k=0;
		cin >> n >> k;
		if(n==0) break;
		int a[n+1]={00},b[n]={00},c[n]={00},max;
		for(int i=0;i<n;i++){
			cin >> a[i+1];
		}
		for(int i=0;i<n-1;i++){
			b[i+1]=b[i]+a[i+1];
		}
		for(int i=0;i<n-1;i++){
			c[i+1]=b[i+k]-b[i];
		}
		max=c[0];
		for(int i=0;i<n;i++){
			if(max<c[i]){
				max=c[i];
			}
		}
		cout << max << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int num[100000];
int main() {
	while(true){
	int n,k;
	if(n==k && n==0)
		break;
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> num[i];
	}
	int now=0,maxer=0;
	for(int i=0;i<k;i++){
		now+=num[i];
	}
	maxer=now;
	for(int i=k;i<n;i++){
		now+=num[i]-num[i-k];
		maxer=max(maxer,now);
	}
	cout << maxer << 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\n650404" ;
	
return 0;
}

C++: #include<cstdio>
#include<string>
#include<vector>
#include<sstream>
#include<deque>
#include<algorithm>
#include<queue>

using namespace std;

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

int ini[10001];
int main(){
	while(1){
		int n,m;
		scanf("%d%d",&n,&m);
		if(n==0)break;
		rep(i,n){
			scanf("%d",&ini[i]);
		}
		
		int sum=0;
		rep(i,m){
			sum+=ini[i];
		}
		
		int maxi=sum;
		for(int i=m;i<n;i++){
			sum-=ini[i-m];
			sum+=ini[i];
			maxi=max(maxi,sum);
		}
		
		printf("%d\n",maxi);
	}
}