LRUD Instructions 2

AtCoder
IDabc291_c
Time2000ms
Memory256MB
Difficulty
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). ## 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`. ## Input The input is given from Standard Input in the following format: $N$ $S$ [samples]
Samples
Input #1
5
RLURU
Output #1
Yes

Takahashi's coordinates change as follows: $(0,0)\to (1,0)\to (0,0)\to (0,1)\to (1,1)\to (1,2)$.
Input #2
20
URDDLLUUURRRDDDDLLLL
Output #2
No
API Response (JSON)
{
  "problem": {
    "name": "LRUD Instructions 2",
    "description": {
      "content": "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",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc291_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Takahashi is on a two-dimensional plane. Starting from the origin, he made $N$ moves.\nThe $N$ moves are represented by a string of length $N$ as described below:\n\n*   Takahashi's coordinates after the...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments