COCI '22 Contest 2 #2 Ekspert

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

The group stage of the World Cup has ended, the teams are ready for the knockout stage, and many experts are trying to figure out the next world champion. One of them is Boris, the man who correctly determined the last four world champions.

Lower the chances of this team because they have a player from Barcelona, raise the chances of that team because they have the captain of Real Madrid... - Boris is calculating - Now I only need to multiply the integers x and y, and then I can announce the next world champion.

The audience suddenly got very quiet. They are impatiently waiting to know if Croatia is going to win.

Boris will multiply x and y using his famous method of four registers.

He has four registers: A, B, C, and D. Initially they have the values: x, y, 0, and 1, respectively. The only operation he is allowed to do is summing up two registers (possibly the same) and storing the result in one of the registers. Each of the registers can have the value of at most 2 \cdot 10^{18}.

He doesn't want the audience to wait too long, so he can make at most 100 such operations.

Help him determine the operations he needs to do and in which of the registers will the final result be stored.

Input Specification

The first and only line contains positive integers x and y (1 \le x \cdot y \le 10^{18}), the numbers Boris needs to multiply.

Output Specification

In the first line, output the integer n (0 \le n \le 100), the number of operations Boris needs to do.

In the i-th of the following n lines output the operation in the format R1 R2 R3, where R_j is the label of the register (A, B, C, or D), and the operation means the sum of R_1 and R_2 will be stored in R_3.

Finally, output a single line with the register (A, B, C, or D) where the final result is stored.

If there are multiple correct solutions, output any of them. The solution doesn't need to have the minimal number of operations.

Constraints

Subtask Points Constraints
1 14 x, y \le 50
2 14 x \cdot y \le 10^4
3 42 No additional constraints.

Sample Input 1

1 2

Sample Output 1

1
A A A
A

Explanation for Sample Output 1

The values of the registers (A, B, C, D) after the i-th operation are:

0: (1, 2, 0, 1) - initial state

1: (2, 2, 0, 1) - after the operation A A A

The product of 1 and 2 is in the register with the label A.

Sample Input 2

3 2

Sample Output 2

6
D C C
D C C
D C C
D C C
D C C
D C C
C

Explanation for Sample Output 2

The values of the registers (A, B, C, D) after the i-th operation are:

0: (3, 2, 0, 1) - initial state

1: (3, 2, 1, 1) - after the operation D C C

2: (3, 2, 2, 1) - after the operation D C C

3: (3, 2, 3, 1) - after the operation D C C

4: (3, 2, 4, 1) - after the operation D C C

5: (3, 2, 5, 1) - after the operation D C C

6: (3, 2, 6, 1) - after the operation D C C

The product of 2 and 3 is in the register with the label C.


Comments

There are no comments at the moment.