CCCGuide

Problem S3: Swipe

2024 · S3 · Original problem · DMOJ

Problem Description

Swipe is a new mobile game that has recently exploded in popularity. In each level of Swipe, you are given 22 rows of integers that can be represented as arrays AA and BB of size NN. The objective of Swipe is to beat each level by turning array AA into array BB.

There are two swipe operations you can perform on array AA.

For example, starting with array A=[0,1,2,3,4,5]A = [0,1,2,3,4,5], if we swipe right on [2,4][2,4], we would obtain the array [0,1,2,2,2,5][0,1,2,2,2,5]. If instead, we started with the same array AA, and swiped left on [3,5][3,5], we would obtain the array [0,1,2,5,5,5][0,1,2,5,5,5]. Note that these arrays are 00-indexed.

Unfortunately, the game is bugged and contains levels that are impossible to beat. Determine if it is possible to transform array AA into array BB. If it is possible, determine a sequence of swipe operations that transforms array AA into array BB.

Input Specification

The first line of input will consist of one positive integer NN, representing the length of each of the two arrays of integers.

The second line of input contains NN space separated integers contained in array AA.

The third line of input contains NN space separated integers contained in array BB.

The following table shows how the available 1515 marks are distributed:

MarksBounds on NNBounds on AiA_i and BiB_i
22N=2N=21≤Ai,Bi≤31 \le A_i,B_i \leq 3
441≤N≤81 \le N \le 81≤Ai,Bi≤81 \le A_i,B_i \leq 8
441≤N≤5001 \le N \le 5001≤Ai,Bi≤30001 \le A_i,B_i \leq 3000
551≤N≤300 0001 \le N \le 300\,0001≤Ai,Bi≤300 0001 \le A_i,B_i \leq 300\,000

Note that for a subtask worth MM marks, you will receive ⌊M2⌋\left\lfloor \frac{M}{2} \right\rfloor marks for a solution that only correctly outputs the first line of output.

Output Specification

The first line of output will contain YES if there is a sequence of swipes that can transform array AA into array BB; otherwise, the first line of output will contain NO.

If the first line of output is YES, the next line contains a non-negative integer KK (K≤NK \leq N), indicating the number of swipes.

Each of the next KK lines contain three space-separated values: DjD_j, ℓj\ell_j, and rjr_j. The value DjD_j will be either R or L, indicating that the jjth swipe is either a right or left swipe, respectively. The values ℓj\ell_j and rjr_j indicate the left-end and right-end of the swipe where 0≤ℓj≤rj<N0 \le \ell_j \le r_j < N.

Sample Input 1

3
3 1 2
3 1 1

Output for Sample Input 1

YES
1
R 1 2

Sample Input 2

4
1 2 4 3
1 4 2 3 

Output for Sample Input 2

NO

Sample Input 3

4
2 1 4 3
2 1 4 3 

Output for Sample Input 3

YES
0