#K34877. Robot Return to Origin

    ID: 25407 Type: Default 1000ms 256MiB

Robot Return to Origin

Robot Return to Origin

You are given a string representing a sequence of commands, where each character is one of the following:

  • 'U': move up
  • 'D': move down
  • 'L': move left
  • 'R': move right

The robot starts at the origin \((0,0)\) on a plane. It executes the given sequence of commands once. If after executing the sequence, the robot returns to the origin (i.e. the net movement is zero both in the x and y directions), then output 1 as the minimum number of repetitions required. Otherwise, output -1, indicating that even repeating the commands infinitely many times the robot will never return to the origin.

Note that the command sequence is repeated infinitely, but the only moment when the robot is checked is after a full execution of the sequence. Hence, the answer is 1 if the sequence is balanced and -1 otherwise.

inputFormat

The input consists of a single line containing a non-empty string commands composed only of the characters 'U', 'D', 'L', and 'R'.

The input is read from standard input (stdin).

outputFormat

Output a single integer: 1 if the robot returns to the origin after one repetition of the commands, or -1 otherwise. The output should be written to standard output (stdout).

## sample
LR
1