#K84892. Robot Return to Origin
Robot Return to Origin
Robot Return to Origin
A robot starts at the origin, \( (0,0) \), on a 2D plane. The robot is given a string \( S \) consisting of characters 'U', 'D', 'L', and 'R', where:
- 'U' moves the robot up (i.e., increases the \( y \) coordinate by 1).
- 'D' moves the robot down (i.e., decreases the \( y \) coordinate by 1).
- 'L' moves the robot left (i.e., decreases the \( x \) coordinate by 1).
- 'R' moves the robot right (i.e., increases the \( x \) coordinate by 1).
Your task is to determine if the robot returns to the origin \( (0,0) \) after executing all the moves provided in \( S \). If the robot ends up back at the origin, output YES
; otherwise, output NO
.
For example, if \( S = "UD" \), the robot moves up and then down, returning to \( (0,0) \), so the output should be YES
.
inputFormat
The input consists of a single line containing a non-empty string \( S \). The string \( S \) is composed only of the characters 'U', 'D', 'L', and 'R'.
Input is provided via stdin.
outputFormat
Output a single line: YES
if the robot returns to the origin \( (0,0) \) after executing the moves in \( S \), otherwise output NO
.
Output should be printed to stdout.
## sampleUD
YES