atcoder#ARC147B. [ARC147B] Swap to Sort
[ARC147B] Swap to Sort
Score : points
Problem Statement
You are given a permutation of .
You can repeat the following two kinds of operations in any order to make sorted in increasing order.
- Operation : Choose an integer such that , and swap and .
- Operation : Choose an integer such that , and swap and .
Find a sequence of operations with the following property:
- The number of Operations is the minimum possible.
- The total number of operations is not larger than .
Under the Constraints of this problem, we can prove that a solution always exists.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Let be the number of operations in your answer. Print lines.
The first line should contain .
The -th () line should contain the following:
A i
if the -th operation is Operation , and the integer chosen in this operation is .B i
if the -th operation is Operation , and the integer chosen in this operation is .
If there are multiple solutions satisfying the condition, printing any of them will be accepted.
4
3 2 4 1
4
A 3
B 1
B 2
B 2
In this Sample Output, changes like this: $(3,2,4,1) \rightarrow (3,2,1,4) \rightarrow (1,2,3,4) \rightarrow (1,4,3,2) \rightarrow (1,2,3,4)$.
Note that you don't have to minimize the total number of operations.
3
1 2 3
0
6
2 1 4 3 6 5
3
A 1
A 3
A 5