atcoder#AGC033B. [AGC033B] LRUD Game

[AGC033B] LRUD Game

Score : 600600 points

Problem Statement

We have a rectangular grid of squares with HH horizontal rows and WW vertical columns. Let (i,j)(i,j) denote the square at the ii-th row from the top and the jj-th column from the left. On this grid, there is a piece, which is initially placed at square (sr,sc)(s_r,s_c).

Takahashi and Aoki will play a game, where each player has a string of length NN. Takahashi's string is SS, and Aoki's string is TT. SS and TT both consist of four kinds of letters: L, R, U and D.

The game consists of NN steps. The ii-th step proceeds as follows:

  • First, Takahashi performs a move. He either moves the piece in the direction of SiS_i, or does not move the piece.
  • Second, Aoki performs a move. He either moves the piece in the direction of TiT_i, or does not move the piece.

Here, to move the piece in the direction of L, R, U and D, is to move the piece from square (r,c)(r,c) to square (r,c1)(r,c-1), (r,c+1)(r,c+1), (r1,c)(r-1,c) and (r+1,c)(r+1,c), respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than NN steps are done.

Takahashi wants to remove the piece from the grid in one of the NN steps. Aoki, on the other hand, wants to finish the NN steps with the piece remaining on the grid. Determine if the piece will remain on the grid at the end of the game when both players play optimally.

Constraints

  • 2H,W2×1052 \leq H,W \leq 2 \times 10^5
  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1srH1 \leq s_r \leq H
  • 1scW1 \leq s_c \leq W
  • S=T=N|S|=|T|=N
  • SS and TT consists of the four kinds of letters L, R, U and D.

Input

Input is given from Standard Input in the following format:

HH WW NN

srs_r scs_c

SS

TT

Output

If the piece will remain on the grid at the end of the game, print YES; otherwise, print NO.

2 3 3
2 2
RRL
LUD
YES

Here is one possible progress of the game:

  • Takahashi moves the piece right. The piece is now at (2,3)(2,3).
  • Aoki moves the piece left. The piece is now at (2,2)(2,2).
  • Takahashi does not move the piece. The piece remains at (2,2)(2,2).
  • Aoki moves the piece up. The piece is now at (1,2)(1,2).
  • Takahashi moves the piece left. The piece is now at (1,1)(1,1).
  • Aoki does not move the piece. The piece remains at (1,1)(1,1).
4 3 5
2 2
UDRRR
LLDUD
NO
5 6 11
2 1
RLDRRUDDLRL
URRDRLLDLRD
NO