#K43467. Circular Movement Checker

    ID: 27316 Type: Default 1000ms 256MiB

Circular Movement Checker

Circular Movement Checker

You are given a sequence of moves represented as a string consisting solely of the characters U (up), D (down), L (left) and R (right). The task is to determine whether the sequence of moves is circular, i.e., whether starting from the origin \( (0, 0) \) and performing the moves in order, you return to the origin.

The sequence is considered valid only if it contains exclusively the characters U, D, L and R and is non-empty. If the string is empty or contains any invalid character, the output should be False.

The final position is computed by considering that each move updates the coordinates as follows:

  • U: \( y = y + 1 \)
  • D: \( y = y - 1 \)
  • L: \( x = x - 1 \)
  • R: \( x = x + 1 \)

If the final coordinates \( (x, y) \) equal \( (0, 0) \), then the sequence is circular.

inputFormat

The input consists of a single line containing a non-empty string representing the sequence of moves. The string may include characters other than U, D, L and R, in which case the output should be False.

Input is provided via stdin.

outputFormat

Output a single line to stdout which is either True if the sequence forms a circular path or False otherwise.

## sample
UDLR
True