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>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#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 CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
#define int ll
signed main(){
    int n,m;
    while(cin>>n>>m,n+m){
        vi v(n+1,0);
        vi dp(n+1,0);
        int ans=-INF;
        rep(i,n)cin>>v[i];
        rep(i,n){
            if(i<=2){
                for(int k=m-1; k>=1;k--)dp[i+k]+=v[i];
            }else{
                dp[i]+=v[i];
                ans=max(ans,dp[i]);
                if(i<n-m-1)
                    for(int j=1;j<=m-1;j++)dp[i+j]+=v[i];
            }
        }
        //rep(i,n)cout<<dp[i]<<endl;
        cout<<ans<<endl;
        
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
    for(int count = 0;  count < 5; count++){
	    vecotor<int> none(2);
	    int N, k;
	    cin >> N >> k;
	    vector<int> a(N);
	    for(int i = 0; i < N; i++){
		cin >> a.at(i);
	    }
	    int ans = 0;
	    int total = 0;
	    for(int i = 0; i < N; i++){
	    	if(i < k) total += a[i];
		else total = total + a[i] - a[i-k];
		if(ans < total) ans = total;
	    }
	    cout << ans << endl;
	    for(int i = 0; i < 2; i++){
    	    cin >> none.at(i);
	    }
　　}
}

C++: #include <iostream>
using namespace std;
int n,k;
int a[100001];
int maxsum,sum;

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

C++: #include <stdio.h>
int array[10000],n,k,max;

void func(int now){
	int i,j,temp=0;
	
	if(now==n-k)return;
	
	for(i=now;i<now+k;i++){
		temp+=array[i];
	}
	if(temp>max)max=temp;
	func(now+1);
}
		
		


int main(void){
	int i;
	
	while(scanf("%d",&n),n){
		max=0;
		
		scanf("%d",&k);
		for(i=0;i<n;i++){
			scanf("%d",&array[i]);
		}
		func(0);
		
		printf("%d\n",max);
		
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;

// 1indexed1dimention[l,r]
class imos1d{
    public:
    vector<ll>t, v;
    ll num;
    ll flg;
    imos1d(ll NUM = 0){
        flg = 0;
        num = NUM + 10;
        v = vector<ll>(num, 0);
        t = vector<ll>(num, 0);
    }
    void add(ll idx, ll x){
        flg = 0;
        t[idx] += x;
    }
    void make(){
        flg = 1;
        for(ll i = 1; i < num; i++)v[i] = v[i - 1] + t[i];
    }
    ll sum(ll l, ll r){
        if(!flg)make();
        return v[r] - v[l - 1];
    }
};

class bit1d{
    public:
    vector<ll>v;
    ll num;
    bit1d(ll NUM = 0){
        num = NUM + 10;
        v = vector<ll>(num, 0);
    }
    void add(ll idx, ll x){
        if(idx == 0)return;
        while(idx <= num){
            v[idx] += x;
            idx += idx & -idx;
        }
    }
    ll sum_of_1_to_idx(ll idx){
        if(idx <= 0)return 0;
        ll s = 0;
        while(idx > 0){
            s += v[idx];
            idx -= idx & -idx;
        }
        return s;
    }
    ll sum(ll l, ll r){
        return sum_of_1_to_idx(r) - sum_of_1_to_idx(l - 1);
    }
};

int main(){
    
    for(ll N, K; cin >> N >> K, N;){
        imos1d data(N);
        for(ll i = 1; i <= N; i++){
            ll x;
            cin >> x;
            data.add(i, x);
        }
        ll ans = data.sum(1, K);
        for(ll l = 1, r = K; r <= N; l++, r++){
             ll tmp = data.sum(l, r);
             ans = max(ans, tmp);
        }
        cout << ans << endl;
    }
    
    return 0;
}

C++: #include<stdio.h>

#include<algorithm>


using namespace std ;



int main()
{
	int n ,k ;

	while( 1 )
	{
		scanf( "%d %d" ,&n ,&k ) ;


		if( !( n | k ) )
		{
			return 0 ;
		}


		int if_k = k - 1 ;

		int ans = -10001 ,other[ 100000 ] ;
		
		int sum = 0 ;

		int i ;
		for( i = 0 ; i < n ; ++i )
		{
			scanf( "%d" ,&other[ i ] ) ;

			sum += other[ i ] ;


			if( i > if_k )
			{
				sum -= other[ i - k ] ;
			}


			ans = max( ans ,sum ) ;
		}


		printf( "%d\n" ,ans ) ;
	}
}

C++: #include <stdio.h>
int RB[100005],ans;
int main() {int N,K,i,j=0;scanf("%d %d",&N,&K);for (i=0;i<K;i++) scanf("%d",&RB[i]),j+=RB[i];ans=j,i=0,N-=K;while (N--) {j-=RB[i];scanf("%d",&RB[i]);j+=RB[i];if (ans<j) ans=j;i=(i+1)%K;} printf("%d\n",ans);return 0;}

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

int main(){
  int n,k;
  while( cin >> n >> k,n+k){
    
    int a[n];
    for(int i = 0;i < n;i++){
      cin >> a[i];
    }
    int sum = -500000;
    for(int i = 0;i < n-k+1;i++){
      cout << i << endl;
      int s = 0;
      for(int j = i;j < i+k;j++){
	s += a[j];
      }
      sum = max(s,sum);
    }
    cout << sum <<  endl;
    
  }
  
}

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<stdio.h>

int main(void){
	int i,n,k,sum,max;
	int N[15000];

	while(0==0){
		scanf("%d %d",&n,&k);
		sum=0;
		if(n==0 && k==0) break;

		for(i=0;i<n;i++)
			scanf("%d",&N[i]);

		for(i=0;i<k;i++)
		    sum+=N[i];//初期値
		
		max=sum;

		for(i=k;i<n;i++){
			sum+=N[i];
			sum-=N[i-k];//前回のｋ個の連続した数の合計から次のｋ個の連続した数こ合計を計算する
			if(sum>max)max=sum;
		}

		printf("%d\n",max);
	}
	return 0;
}

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

int main(){
	int n,k,max,buf,*a;
	
	while(1){
		cin >> n >> k;
		
		if(n || k){
			max = 0;
			
			a = new int[n];
			
			for(int i = 0; i < n; i++){
				cin >> a[i];
			}
			
			for(int i = 0; i <= n-k; i++){
				buf = 0;
				
				for(int j = 0; j < k; j++){
					buf += a[i+j];
				}
				
				if(max < buf){
					max = buf;
				}
			}
			
			cout << max << endl;
		}else{
			break;
		}
	}
	
	return 0;
}

C++: #include<iostream>
main(){
  for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))
    for(M=1<<31,i=s=0;i<n;s+=a[i]-(k<i)*a[i-k],i++,k<i&M<s&&(M=s))std::cin>>a[i];
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
int n;
int k;
int b;
int c;//現在の和
int d;//最高値
while(cin>>n){
if(n==0){break;}
cin>>k;
int a[n];
b=0;
while(b<n){
cin >>a[b];
b=b+1;}
c=0;
b=0;
while(b<k){
c=c+a[b];
b=b+1;}
d=c;
while(b<n){
c=c-a[b-k]+a[b];
if(c>d){d=c;}
b=b+1;}
cout << d<<endl;}
}