atcoder#ABC221G. [ABC221G] Jumping sequence
[ABC221G] Jumping sequence
Score : points
Problem Statement
Consider an infinite two-dimensional coordinate plane. Takahashi, who is initially standing at , will do jumps in one of the four directions he chooses every time: up, down, left, or right. The length of each jump is fixed. Specifically, the -th jump should cover the distance of . Determine whether it is possible to be exactly at after jumps. If it is possible, show one way to do so.
Here, for each direction, a jump of length from takes him to the following point:
- up:
- down:
- left:
- right: .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
In the first line, print Yes
if there is a desired sequence of jumps, and No
otherwise.
In the case of Yes
, print in the second line a desired sequence of jumps as a string of length consisting of U
, D
, L
, R
, as follows:
- if the -th jump is upward, the -th character should be
U
; - if the -th jump is downward, the -th character should be
D
; - if the -th jump is to the left, the -th character should be
L
; - if the -th jump is to the right, the -th character should be
R
.
3 2 -2
1 2 3
Yes
LDR
If he jumps left, down, right in this order, Takahashi moves and ends up at , which is desired.
2 1 0
1 6
No
It is impossible to be exactly at after the two jumps.
5 6 7
1 3 5 7 9
Yes
LRLUR