program xxxx;
var n,k,i,j:longint;
a,min,max:array[1..1000000] of longint;
begin
assign(input,'window.in');
reset(input);
assign(output,'window.out');
rewrite(output);
read(n,k);
if k>n then
begin
min[1]:=maxlongint;
max[1]:=0;
for i:=1 to n do
begin
if a[i]<min[1] then
min[1]:=a[i];
if a[i]>max[1] then
max[1]:=a[i];
end;
end;
for i:=1 to n do
read(a[i]);
for i:=1 to n-k+1 do
begin
max[i]:=0;
min[i]:=maxlongint;
if (max[i-1]<>a[i-1])and(min[i-1]<>a[i-1]) then
begin
if a[i-1+k]>max[i-1] then
max[i]:=a[i-1+k]
else
max[i]:=max[i-1];
if a[i-1+k]<min[i-1] then
min[i]:=a[i-1+k]
else
min[i]:=min[i-1];
continue;
end;
for j:=0 to k-1 do
begin
if a[i+j]>max[i] then
max[i]:=a[i+j];
if a[i+j]<min[i] then
min[i]:=a[i+j];
end;
end;
for i:=1 to n-k do
write(min[i],' ');
writeln(min[n-k+1]);
for i:=1 to n-k do
write(max[i],' ');
writeln(max[n-k+1]);
close(input);
close(output);
end.