9232: ABC291 —— C - LRUD Instructions 2
[Creator : ]
Description
### Problem Statement
Takahashi is on a two-dimensional plane. Starting from the origin, he made $N$ moves.
The $N$ moves are represented by a string of length $N$ as described below:
- Takahashi's coordinates after the $i$-th move are:
- $(x+1,y)$ if the $i$-th character of $S$ is `R`;
- $(x-1,y)$ if the $i$-th character of $S$ is `L`;
- $(x,y+1)$ if the $i$-th character of $S$ is `U`; and
- $(x,y-1)$ if the $i$-th character of $S$ is `D`,
where $(x,y)$ is his coordinates before the move.
Determine if Takahashi visited the same coordinates multiple times in the course of the $N$ moves (including the starting and ending points).
Takahashi is on a two-dimensional plane. Starting from the origin, he made $N$ moves.
The $N$ moves are represented by a string of length $N$ as described below:
- Takahashi's coordinates after the $i$-th move are:
- $(x+1,y)$ if the $i$-th character of $S$ is `R`;
- $(x-1,y)$ if the $i$-th character of $S$ is `L`;
- $(x,y+1)$ if the $i$-th character of $S$ is `U`; and
- $(x,y-1)$ if the $i$-th character of $S$ is `D`,
where $(x,y)$ is his coordinates before the move.
Determine if Takahashi visited the same coordinates multiple times in the course of the $N$ moves (including the starting and ending points).
Input
### Input
The input is given from Standard Input in the following format:
```
$N$
$S$
```
The input is given from Standard Input in the following format:
```
$N$
$S$
```
Output
### Output
Print `Yes` if Takahashi visited the same coordinates multiple times in the course of the $N$ moves; print `No` otherwise.
Print `Yes` if Takahashi visited the same coordinates multiple times in the course of the $N$ moves; print `No` otherwise.
Constraints
### Constraints
- $1 \leq N \leq 2\times 10^5$
- $N$ is an integer.
- $S$ is a string of length $N$ consisting of `R`, `L`, `U`, and `D`.
- $1 \leq N \leq 2\times 10^5$
- $N$ is an integer.
- $S$ is a string of length $N$ consisting of `R`, `L`, `U`, and `D`.
Sample 1 Input
5
RLURU
Sample 1 Output
Yes
Takahashi's coordinates change as follows: (0,0)→(1,0)→(0,0)→(0,1)→(1,1)→(1,2).
Sample 2 Input
20
URDDLLUUURRRDDDDLLLL
Sample 2 Output
No