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.

• 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 1 L 1 1 L 2 1 L 10 2 L 10 1 P 1 1 P 2 1 P 10 2 P 9 

Sample Output

 1 2 3 4 5 6 7 8 1 2 10 9 1 2 10 10 

For this example, the answer is 45.

×