var m,n,i,j:longint;
max,min,a:array[1..100001] of longint;
begin
assign(input,'window.in');reset(input);
assign(output,'window.out');rewrite(output);
readln(n,m);
for i:=1 to n do read(a[i]);
for i:=1 to n do
begin
max[i]:=-maxlongint;
min[i]:=maxlongint;
end;
for i:=1 to n-m+1 do
for j:=0 to m-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;
for i:=1 to n-m+1 do write(min[i],' ');
writeln;
for i:=1 to n-m+1 do write(max[i],' ');
close(input);close(output);
end.