include[HTML_REMOVED]
using namespace std;
const int N=1e6+10;
int a[N],q[N];
int n,k;
int main()
{
int hh=0,tt=-1;
scanf(“%d%d”,&n,&k);
for (int i = 0; i < n; i ) scanf(“%d”, &a[i]);
for(int i=0;i[HTML_REMOVED]q[hh]) hh;
while(hh<=tt&&a[q[tt]]>=a[i]) tt--;
q[++tt]=i;
if(i>=k-1) printf("%d ",a[q[hh]]);
}
puts(" ");
tt=-1,hh=0;
for(int i=0;i<n;i++) {
if(hh<=tt&&i-k+1>q[hh]) hh++;
while(hh<=tt&&a[q[tt]]<=a[i]) tt--;
q[++tt]=i;
if(i>=k-1) printf("%d ",a[q[hh]]);
}
}