One summer day, April bought
Initially, the candy pieces were lined up in a straight line. However, April wants to change the order of the candies by taking any piece of candy, and placing it either at the front or back of the line. Given the order April wants to place the candies in, find the minimum number of moves needed to place them in that arrangement.
Input Specification
The first line contains an integer
The next line contains a sequence of
The final line contains
Constraints
For all subtasks:
Subtask 1 [10%]
Subtask 2 [30%]
Subtask 3 [60%]
Output Specification
On the first line, output a single integer
On the next F i
to move the B i
to move the
If there are multiple possible ordering of operations you may output any of them. It is guaranteed that it is always possible to rearrange the candy.
Sample Input 1
5
1 2 3 4 5
5 2 3 4 1
Sample Output 1
2
F 5
B 2
Explanation for Sample Output 1
April can move the candy with sourness value
The only other solution is
2
B 1
F 4
Sample Input 2
4
4 3 5 2
5 3 4 2
Sample Output 2
2
F 2
F 3
Explanation for Sample Output 2
April can move the candy with sourness value
Comments