Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a…
- User
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all:
- 'U': go up, (x, y) → (x, y+1);
- 'D': go down, (x, y) → (x, y-1);
- 'L': go left, (x, y) → (x-1, y);
- 'R': go right, (x, y) → (x+1, y).
The robot will do the operations in s from left to right, and repeat it infinite times. Help Fox Ciel to determine if after some steps the robot will located in (a, b). Input
The first line contains two integers a and b, ( - 109 ≤ a, b ≤ 109). The second line contains a string s (1 ≤ |s| ≤ 100, s only contains characters 'U', 'D', 'L', 'R') — the command.
Output
Print "Yes" if the robot will be located at (a, b), and "No" otherwise.
Examples
Input
2 2 RU
Output
Yes
Input
1 2 RU
Output
No
Input
-1 1000000000 LRRLU
Output
Yes
Input
0 0 D
Output
Yes
Note
In the first and second test case, command string is "RU", so the robot will go right, then go up, then right, and then up and so on.
The locations of its moves are (0, 0) → (1, 0) → (1, 1) → (2, 1) → (2, 2) → ...
So it can reach (2, 2) but not (1, 2).
Assistant
pythona, b = map(int, input().split()) s = input().strip() dx_total = 0 dy_total = 0 positions = [(0, 0)] x, y = 0, 0 for c in s: if c == 'U': y += 1 elif c == 'D': y -= 1 elif c == 'R': x += 1 elif c == 'L': x -= 1 positions.append((x, y)) dx_total = x dy_total = y for (xk, yk) in positions: if xk == a and yk == b: print("Yes") exit() delta_x = a - xk delta_y = b - yk if dx_total == 0 and dy_total == 0: continue if dx_total == 0: if delta_x != 0: continue if dy_total == 0: continue if (delta_y % dy_total) != 0: continue n = delta_y // dy_total if n >= 0: print("Yes") exit() elif dy_total == 0: if delta_y != 0: continue if (delta_x % dx_total) != 0: continue n = delta_x // dx_total if n >= 0: print("Yes") exit() else: if (delta_x % dx_total) != 0 or (delta_y % dy_total) != 0: continue n_x = delta_x // dx_total n_y = delta_y // dy_total if n_x == n_y and n_x >= 0: print("Yes") exit() print("No")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.