Takahashi will do a tap dance. The dance is described by a string S where each character…
- User
Takahashi will do a tap dance. The dance is described by a string S where each character is
L,R,U, orD. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character.S is said to be easily playable if and only if it satisfies both of the following conditions:
- Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is
R,U, orD. - Every character in an even position (2-nd, 4-th, 6-th, \ldots) is
L,U, orD.
Your task is to print
Yesif S is easily playable, andNootherwise.Constraints
- S is a string of length between 1 and 100 (inclusive).
- Each character of S is
L,R,U, orD. Input
Input is given from Standard Input in the following format:
S
Output
Print
Yesif S is easily playable, andNootherwise.Examples
Input
RUDLUDR
Output
Yes
Input
DULL
Output
No
Input
UUUUUUUUUUUUUUU
Output
Yes
Input
ULURU
Output
No
Input
RDULULDURURLRDULRLR
Output
Yes
- Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is
Assistant
We need to check if the string S satisfies: all characters at odd indices (1-indexed) are one of R, U, D; and all characters at even indices are one of L, U, D.
We just iterate over indices (0-indexed if using Python) and check accordingly.
Given the constraints, trivial.
Let's produce a solution in Python.
We'll read S from input, then iterate through characters with index i (starting 0). If (i % 2 == 0) => odd position (1-indexed), allowed set = {'R','U','D'}. Else allowed set = {'L','U','D'}. If any character not in allowed set, print "No" and exit. Otherwise, print "Yes".
Edge cases: length 1, check only first char.
Now the examples:
- RUDLUDR: positions:1 R ok,2 U ok (even allows U),3 D ok,4 L ok (even allows L),5 U ok,6 D ok (even allows D),7 R ok -> Yes.
- DULL: 1 D ok,2 U ok,3 L -> odd position must be R,U,D but L is not allowed -> No.