#K46132. Return to Origin

    ID: 27909 Type: Default 1000ms 256MiB

Return to Origin

Return to Origin

You are given a sequence of moves, where each character represents a step in one of four cardinal directions: U (up), D (down), L (left), and R (right). Your task is to determine if, after executing all moves, you return to the origin (0,0).

The position after performing the moves can be mathematically expressed as: \( (x,y) = \left(\sum_{i=1}^{n} \Delta x_i, \sum_{i=1}^{n} \Delta y_i\right) \), where \( \Delta x_i \) and \( \Delta y_i \) correspond to the horizontal and vertical changes for each move. You should output YES if the final position is (0,0); otherwise, output NO.

Note: An empty move sequence implies that you remain at the origin.

inputFormat

The first line of the input contains an integer \(T\), the number of test cases. Each of the following \(T\) lines contains a string of characters (with no spaces) representing the sequence of moves.

For example:

2
UD
LLRR

outputFormat

For each test case, output one line containing either YES if the movements return to the origin, or NO otherwise.

For the sample input above, the correct output is:

YES
YES
## sample
2
UD
LLRR
YES

YES

</p>