Robot
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Recently, Petryk’s parents gave him a programmable robot. Initially, the robot is located at the point with coordinates (0, 0). Petryk inputs a set of commands into the robot, which it executes sequentially from the first to the last. There are two types of commands:
U— move 1 step up, i.e., from point (\(x\), \(y\)) to point (\(x\), \(y+1\)).R— move 1 step right, i.e., from point (\(x\), \(y\)) to point (\(x+1\), \(y\)).
Petryk programmed the robot with a sequence of commands \(s_1\), \(s_2\), ..., \(s_n\). You are given this sequence, as well as a pair of numbers \(x\) and \(y\).
Determine whether Petryk can rearrange the commands so that the robot passes through the point (\(x\), \(y\)).
Input
The first line contains a string \(s\) consisting of \(n\) characters, which correspond to the commands entered by Petryk.
The second line contains two integers \(x\) and \(y\).
Output
In a single line, output YES if Petryk can rearrange the
commands so that the robot passes through the point (\(x\), \(y\)).
If it is impossible to reach the target, output NO.
Constraints
\(1 \le n \le 1000\), where \(n\) is the length of the given string,
\(0 \le x, y \le 1000\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| RURU 2 0 | YES |
| Input (stdin) | Output (stdout) |
|---|---|
| RRRRRR 1 1 | NO |
Notes
In the first example, Petryk can form the sequence of commands
RRUU by swapping the second and third commands.
Then the robot will visit the following points: (0, 0) \(\rightarrow\) (1, 0) \(\rightarrow\) (2, 0) \(\rightarrow\) (2, 1) \(\rightarrow\) (2, 2).
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|