#include<cstdio> using namespace std; #define N 1000001 int n,K,a[N],head=1,tail=1,q[N],ans[N]; int main() { scanf("%d%d",&n,&K); for(int i=1;i<=n;++i) scanf("%d",&a[i]); q[1]=1; for(int i=2;i<=K;++i) { while(a[i]<=a[q[tail]] && tail>=head) --tail; q[++tail]=i; } ans[1]=a[q[head]]; for(int i=K+1;i<=n;++i) { if(q[head]<i-K+1) ++head; while(a[i]<=a[q[tail]] && tail>=head) --tail; q[++tail]=i; ans[i-K+1]=a[q[head]]; } for(int i=1;i<=n-K;++i) printf("%d ",ans[i]); printf("%d ",ans[n-K+1]); head=tail=1; q[1]=1; for(int i=2;i<=K;++i) { while(a[i]>=a[q[tail]] && tail>=head) --tail; q[++tail]=i; } ans[1]=a[q[head]]; for(int i=K+1;i<=n;++i) { if(q[head]<i-K+1) ++head; while(a[i]>=a[q[tail]] && tail>=head) --tail; q[++tail]=i; ans[i-K+1]=a[q[head]]; } for(int i=1;i<=n-K;++i) printf("%d ",ans[i]); printf("%d ",ans[n-K+1]); return 0; }