문제
For the new year, Farmer John decided to give his cows a festive binary search tree (BST)!
To generate the BST, FJ starts with a permutation
generate(l,r):
if l > r, return empty subtree;
x = argmin_{l <= i <= r} a_i; // index of min a_i in {a_l,...,a_r}
return a BST with x as the root,
generate(l,x-1) as the left subtree,
generate(x+1,r) as the right subtree;
For example, the permutation
4
/ \
2 5
/ \
1 3
Let
The number of inversions of
BATCHING:
Test cases 3-4 satisfy
N\le 8. Test cases 5-7 satisfy
N\le 20. Test cases 8-10 satisfy
N\le 50.
Problem credits: Yinzhan Xu
입력
The only line of input consists of three space-separated integers
출력
Print
예제1
3 0 192603497
1 2 3
Here, the only permutation is
예제2
3 1 144408983
3 4 4
Here, the two permutations are