#include<iostream> #include<cstdio> using namespace std; const int maxn=1000005; struct qwq{ int pos; int val; }; int kd(){ int r=0, f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0'&&c<='9'){ r=(r<<1)+(r<<3)+c-'0'; c=getchar(); } return f*r; } int ansd[maxn], ansx[maxn]; qwq d[maxn], x[maxn]; int n, k, sum, num; int dt, dw, xt, xw; int main(){ n=kd(); k=kd(); dt=dw=0; xt=xw=0; sum=0; for(int i=0; i<n; i++){ while(dt<dw && i-d[dt].pos>=k) dt++; while(xt<xw && i-x[xt].pos>=k) xt++; num=kd(); while(dt<dw && d[dw-1].val<=num) dw--; d[dw].pos=i; d[dw].val=num; dw++; while(xt<xw && x[xw-1].val>=num) xw--; x[xw].pos=i; x[xw].val=num; xw++; ansd[sum]=d[dt].val; ansx[sum]=x[xt].val; sum++; } for(int i=k-1; i<n; i++){ cout<<ansx[i]<<" "; } cout<<endl; for(int i=k-1; i<n; i++){ cout<<ansd[i]<<" "; } return 0; }