Chaotic Sequence
10 students are standing in a row. From left to right, they are labeled as 1 to 10. When the teacher left for the bathroom, they start to switch positions. When the teacher come back on the \(k^\text{th}\) minute, the queue becomes the \(k^\text{th}\) lexicography order.
The teacher needs your help to answer 2 types of queries:
K L N
: On the \(k^\text{th}\) minute, what is the label of the \(n^\text{th}\) person from the left?K P N
: On the \(k^\text{th}\) minute, what is the position of the person labeled \(n\)?
This file contains 1000 queries. What is the sum of all output?
Sample Input
1 2 3 4 5 6 7 8 

Sample Output
1 2 3 4 5 6 7 8 

For this example, the answer is 45.