}
//二分法
#include<stdio.h>
struct node { int index,f; }pmax[1100000],pmin[1100000]; int a[1100000]; int qiulinjie(int front ,int last,int d) { int mid;while(front<=last) { mid=(front+last)/2;if(pmin[mid].f==d)return mid;elseif(pmin[mid].f>d)last=mid-1;elsefront=mid+1;}return front; } int qiulinjie1(int front ,int last,int d) { int mid;while(front<=last) { mid=(front+last)/2;if(pmax[mid].f==d)return mid;elseif(pmax[mid].f<d)last=mid-1;elsefront=mid+1;}return front; } int main() { int front,last,i,j,k,n,m;while(scanf("%d%d",&n,&k)!=EOF) { for(i=1;i<=n;i++)scanf("%d",&a[i]);front=last=1;pmin[front].index=1; pmin[last].f=a[1]; for(i=2;i<=k;i++) { last=qiulinjie(front,last,a[i]); pmin[last].index=i; pmin[last].f=a[i]; } printf("%d",pmin[front].f); for(;i<=n;i++) { last=qiulinjie(front,last,a[i]); pmin[last].index=i; pmin[last].f=a[i]; while(i-pmin[front].index>=k) front++; printf(" %d",pmin[front].f); } printf("\n");front=last=1;pmax[front].index=1; pmax[front].f=a[1]; for(i=2;i<=k;i++) { last=qiulinjie1(front,last,a[i]); pmax[last].index=i; pmax[last].f=a[i]; } printf("%d",pmax[front].f); for(;i<=n;i++) { last=qiulinjie1(front,last,a[i]); pmax[last].index=i; pmax[last].f=a[i]; while(i-pmax[front].index>=k) front++; printf(" %d",pmax[front].f); } printf("\n");} return 0;}