#P5868. [SEERC 2018] Min Max Convert

[SEERC 2018] Min Max Convert

Description

AA is an array with NN elements. You can perform the following two operations on this array:

  1. Choose an index interval [a,b] (1abN)[a, b] \ (1 \leq a \leq b \leq N). Let the maximum value among the elements in this interval be xx, and replace all elements in this interval with xx.
  2. Choose an index interval [a,b] (1abN)[a, b] \ (1 \leq a \leq b \leq N). Let the minimum value among the elements in this interval be xx, and replace all elements in this interval with xx.

Compute a sequence of operations that transforms array AA into another given array BB (also with NN elements). The number of operations in the sequence must be less than or equal to 2N2N.

Input Format

The first line contains an integer NN.

The second line contains an array AA with NN elements.

The third line contains another array BB with NN elements.

Output Format

If there is no solution, output 1-1. Otherwise, output an integer xx in the first line, representing the minimum number of operations needed to transform array AA into BB. In the next xx lines, each line contains one character (representing the type of operation, m means the minimum-value operation is used, and M means the maximum-value operation is used) and an interval (a,b)(a,b), describing each operation. If there are multiple solutions, output any one of them.

5
1 5 5 3 4
1 1 4 4 4
3
m 1 2
M 4 5
m 3 5
5
1 2 3 4 4
2 2 2 2 5
-1

Hint

  • 1N100,0001 \leq N \leq 100, 000.
  • All elements in arrays AA and BB are integers in the interval [1,N][1, N].

Translated by ChatGPT 5