Bob has painstakingly written
Bob takes the top page of the first pile and creates a new pile with it. He then takes the new top page of the first pile and chooses to either place it at the top of the second pile or the bottom. He keeps doing this until all the pages are now in the second pile. Bob defines this series of operations as a single restacking. He performs this restacking with the new pile until he has a sorted pile of the
Given the original pile, can you help Bob sort his physics homework? Bob is busy with other homework, so he asks that your sort takes at most
Constraints
For all
Each number from
Subtask 1 [10%]
Subtask 2 [10%]
Subtask 3 [80%]
Input Specification
The first line will contain two space-separated integers,
The next line will contain
Output Specification
On the first line, output a single integer
On the next T
to move the current top page to the top of the new pile, or B
to move it to the bottom of the new pile.
If these specifications are not satisfied or if your instructions do not sort the pile, you will receive a Wrong Answer
verdict.
Sample Input 1
8 2000
1 5 2 6 3 7 4 8
Sample Output 1
2
BTBTBTB
TTTBBBB
Explanation for Sample 1
After the first set of instructions, the pile becomes
4 3 2 1 5 6 7 8
After the second set of instructions, the pile becomes
1 2 3 4 5 6 7 8
So the pages have been sorted.
Sample Input 2
2 2000
1 2
Sample Output 2
0
Comments