#include <bits/stdc++.h>
using namespace std;
int st[5000005][25];
int main(){
int n,m;
cin>>n>>m;
memset(st,1e9,sizeof(st));
for(int i=1;i<=n;i++) cin>>st[i][0];
for(int j=1;j<=20;j++){
for(int i=1;i+(1<<(j-1))-1<=n;i++){
st[i][j]=min(st[i][j-1],st[i+1<<(j-1)][j-1]);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=3;j++){
cout<<st[i][j]<<" ";
}
}
for(int i=1;i<=n;i++){
if (i==1) {
cout<<0<<endl;
continue;
}
int l=max(i-m,1);
int r=i-1;
int k=log2(r-l+1);
cout<<min(st[l][k],st[r-(1<<k)+1][k])<<endl;
}
return 0;
}