As an engineering student, Jack starts to consider a network problem. Jack designs a comparator circuit as the birthday present to Rose, which works by inputting two integers and outputting

, the minimum of the two integers and

, the maximum of the two integers.

Now Jack would like to build a comparator network which can sort integer permutations of size

. This comparator network is divided into

levels, where the

-th level consists of

comparators and many wires. For the

-th comparator of the

-th level, you may choose two locations

,

, and this comparator will compare the two numbers from same locations of
%7D)
-th level and send the minimum of them to the location

and the maximum to the location

of the

-th level. And in the last level the integers should be well sorted in ascending order from location

to

. Note that no two comparators in the same level can share the input from the same location.
When

is very small, Jack easily constructs a comparator network based on bubbling sort, which is illustrated below.
But now he only has

comparators, and he asks you to help him design a better parallel network meeting the requirements.