Fill in the forgotten turns and pick each run length inside its range so the cleaner ends at (X, Y), printing the smallest such log.
Medium6BacktrackingMathNo attempts yetTime limit10sMemory limit1024 MBIchiro won a new model of cleaner as a prize in a programming contest. The cleaner moves around the house on its own and cleans it. The house is large enough to be treated as an infinite two dimensional plane, whose axes are called the x axis and the y axis. When you face the positive direction of the x axis, the positive direction of the y axis is on your left.
The cleaner cleans by performing a sequence of actions. One action consists of a turn and a run. The cleaner first turns 90 degrees to the left or to the right, and then runs straight ahead for an integer length in the direction it faces. At the end of a day the cleaner reports the log of that day's actions to Ichiro.
The cleaner carries an artificial intelligence close to a human one, so it is forgetful like a human. It sometimes forgets the direction of a turn, and it sometimes remembers the length of a run only as a rough range. To pretend that it worked correctly, it still has to hand over a complete log after cleaning.
The cleaner started at the point (0,0) facing the positive direction of the x axis. You are given the position (X,Y) of the cleaner after cleaning and the incomplete log that the cleaner remembers. Recover a complete log that satisfies all of the following conditions.
The direction the cleaner faces after cleaning does not matter, because it can still turn freely once cleaning is over, though it cannot run any more. Ichiro checks only the format of the log and the final position, so you do not have to recover the path the cleaner actually took.
The first line contains three integers N, X, Y (1≤N≤16, −109≤X,Y≤109). N is the number of actions in the incomplete log, and (X,Y) is the position of the cleaner after cleaning.
The i-th of the next N lines contains a character Di and two integers LLi, LUi separated by spaces (1≤LLi≤LUi≤55555555). Di is the direction of the i-th turn, where L means left, R means right, and ? means that the direction was forgotten. LLi and LUi are the lower and the upper bound of the length of the i-th run.
If no log satisfies the conditions, print -1 and nothing else.
Otherwise print the number of actions N on the first line. On the i-th of the next N lines print the direction of the i-th turn and the length of the i-th run, separated by a space. Write L for a left turn and R for a right turn.
Several logs can satisfy the conditions, so print the smallest one under the following order. Compare the directions of the first turns, where L is smaller than R. If they are equal, compare the lengths of the first runs as integers. If those are equal, compare the directions of the second turns, and continue in the same way to the last action.