I. Rikka with Sorting Networks
time limit per test
4.0 s
memory limit per test
1024 MB
input
standard input
output
standard output
Rikka knows that Bubble sort is a simple but beautiful algorithm, Quicksort is a complex but efficient algorithm, and Shellsort is a weird but practical algorithm. Rikka is interested in all sorting algorithms and she can assign as many new problems for ICPC contests as she wants.
Rikka hates those guys who create new problems with the same ideas over and over again, and she hopes not to become the person she hates to be. Though she has already assigned several problems for sorting algorithms such as Merge sort and Insertion sort, she decides to show you the last problem about sorting algorithms to end this series forever.
Here Rikka introduces the sorting network and she defines a comparator at first. For a permutation AA of the nn smallest positive integers denoted by a1,a2,⋯,ana1,a2,⋯,an, a comparator [u,v][u,v] (u≠vu≠v) sorts the uu-th and the vv-th element in AA into nondecreasing order. Formally, a comparator is a mapping [u,v][u,v] satisfying
- [u,v](au)=min(au,av)[u,v](au)=min(au,av); and
- [u,v](av)=max(au,av)[u,v](av)=max(au,av); and
- [u,v](ak)=ak[u,v](ak)=ak for all kk with k≠uk≠u and k≠vk≠v.
Rikka defines a sorting network as a composition of comparators and provides for you a sorting network with kk ordered comparators. Now, Rikka wants you to count the number of permutations of 11 to nn which,