#P9626. Safe Robot Path Reordering

    ID: 22773 Type: Default 1000ms 256MiB

Safe Robot Path Reordering

Safe Robot Path Reordering

A robot is standing on an infinite 2-dimensional plane. It is programmed with a string \(s_1s_2\cdots s_n\) of length \(n\), where each \(s_i\) is one of \(\{U, D, L, R\}\). Starting from \((0,0)\), the robot executes the instructions in order: when \(s_i=U\) it moves to \((x, y+1)\), when \(s_i=D\) it moves to \((x, y-1)\), when \(s_i=L\) it moves to \((x-1, y)\), and when \(s_i=R\) it moves to \((x+1, y)\).

There is a mine buried at coordinate \((m_x, m_y)\). If the robot ever steps on \((m_x, m_y)\) during its journey (including the starting point), it will be destroyed.

Your task is to rearrange the characters of the given instruction string in any order so that the robot's path does not include the mine coordinate \((m_x, m_y)\). If no such rearrangement exists, output -1.

Note: The instructions can be rearranged arbitrarily. If multiple solutions exist, you may print any one of them.

inputFormat

The first line contains a non-empty string \(s\) consisting of characters ‘U’, ‘D’, ‘L’, ‘R\). The second line contains two space-separated integers \(m_x\) and \(m_y\) — the coordinates of the mine.

outputFormat

If a rearrangement exists such that the robot never steps on \((m_x, m_y)\), output one valid rearranged string. Otherwise, output -1.

sample

RULD
1 1
UDRL