Problem:
Score : 600 points

Problem Statement

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

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

The game consists of N steps. The i-th step proceeds as follows:

First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.

Second, Aoki performs a move. He either moves the piece in the direction of T_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) to square (r,c-1), (r,c+1), (r-1,c) and (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 N steps are done.

Takahashi wants to remove the piece from the grid in one of the N steps.
Aoki, on the other hand, wants to finish the N 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

2 \leq H,W \leq 2 \times 10^5

2 \leq N \leq 2 \times 10^5

1 \leq s_r \leq H

1 \leq s_c \leq W

|S|=|T|=N

S and T consists of the four kinds of letters L, R, U and D.

Input

Input is given from Standard Input in the following format:

H W N
s_r s_c
S
T

Output

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

Sample Input 1

2 3 3
2 2
RRL
LUD

Sample Output 1

YES

Here is one possible progress of the game:

Takahashi moves the piece right. The piece is now at (2,3).

Aoki moves the piece left. The piece is now at (2,2).

Takahashi does not move the piece. The piece remains at (2,2).

Aoki moves the piece up. The piece is now at (1,2).

Takahashi moves the piece left. The piece is now at (1,1).

Aoki does not move the piece. The piece remains at (1,1).

Sample Input 2

4 3 5
2 2
UDRRR
LLDUD

Sample Output 2

NO

Sample Input 3

5 6 11
2 1
RLDRRUDDLRL
URRDRLLDLRD

Sample Output 3

NO

Solution in Ruby (2.3.3) (judge verdict: Wrong Answer)

#!/usr/bin/env ruby

UP=1
DOWN=2
LEFT=3
RIGHT=4

def safe_add(array, position, updown_flag)
  threshold = updown_flag ? H : W
  if 0 <= position and position < threshold
    array << position
  end
end

def first_move_only(array, i, direction)
  case direction
  when UP
    offset = 1
    updown_flag = true
  when DOWN
    offset = -1
    updown_flag = true
  when LEFT
    offset = 1
    updown_flag = false
  when RIGHT
    offset = -1
    updown_flag = false
  end

  array[i+1].each do |place|
    safe_add(array[i], place, updown_flag)
    safe_add(array[i], place + offset, updown_flag)
  end
end

def move_same_direction(array, i, direction)
  case direction
  when UP
    offset_check = -1
    offset_add   = 1
    updown_flag = true
  when DOWN
    offset_check = 1
    offset_add   = -1
    updown_flag = true
  when LEFT
    offset_check = -1
    offset_add   = 1
    updown_flag = false
  when RIGHT
    offset_check = 1
    offset_add   = -1
    updown_flag = false
  end
  threshold = updown_flag ? H : W

  array[i+1].each do |place|
    if place + offset_check < 0 or threshold <= place + offset_check
      safe_add(array[i], place, updown_flag)
      safe_add(array[i], place + offset_add, updown_flag)
    elsif array[i+1].find(place + offset_check)
      safe_add(array[i], place, updown_flag)
    end
  end
end

def move_opposite_direction(array, i, direction)
  case direction
  when UP
    offset_same_direction    = -1
    offset_against_direction = 1
    updown_flag = true
  when DOWN
    offset_same_direction    = 1
    offset_against_direction = -1
    updown_flag = true
  when LEFT
    offset_same_direction    = -1
    offset_against_direction = 1
    updown_flag = false
  when RIGHT
    offset_same_direction    = 1
    offset_against_direction = -1
    updown_flag = false
  end
  threshold = updown_flag ? H : W

  array[i+1].each do |place|
    check_position1 = place + offset_against_direction
    check_position2 = place + offset_same_direction
    if check_position1 < 0 or threshold <= check_position1
      safe_add(array[i], place, updown_flag)
    elsif array[i+1].find(check_position1)
      safe_add(array[i], place, updown_flag)
    elsif check_position2 < 0 or threshold <= check_position2
      # nothing to do
    elsif array[i+1].find(check_position2)
      safe_add(array[i], place, updown_flag)
    end
  end
end

def copy_the_last(array, i)
  array[i] = array[i+1]
end


if $0 == __FILE__
  H, W, N = gets.split(' ').map &:to_i
  Sr, Sc = gets.split(' ').map &:to_i

  S = []
  gets.chomp.split('').each do |s|
    case s
    when 'U'
      S << UP
    when 'D'
      S << DOWN
    when 'L'
      S << LEFT
    when 'R'
      S << RIGHT
    end
  end
  T = []
  gets.chomp.split('').each do |s|
    case s
    when 'U'
      T << UP
    when 'D'
      T << DOWN
    when 'L'
      T << LEFT
    when 'R'
      T << RIGHT
    end
  end



  # i手開始前に後手(青木君)がいたら負ける位置(上下)
  places_ud = Array.new(N)
  # i手開始前に後手(青木君)がいたら負ける位置(左右)
  places_lr = Array.new(N)

  (N-1).downto(0).each do |i|
    places_ud[i] = []
    places_lr[i] = []
    case S[i]
    when UP
      places_ud[i] << 0
    when DOWN
      places_ud[i] << H-1
    when LEFT
      places_lr[i] << 0
    when RIGHT
      places_lr[i] << W-1
    end

    next if i == N-1

    # 前回(i+1)の負ける位置(対象位置)それぞれについて、
    # 対象位置とその上下左右(対象上下左右位置)を
    # 今回(i)の負ける位置として追加するかどうか
    case S[i]
    when UP
      case T[i]
      when UP
        move_same_direction(places_ud, i, S[i])
      when DOWN
        move_opposite_direction(places_ud, i, S[i])
      when LEFT
        first_move_only(places_ud, i, S[i])
      when RIGHT
        first_move_only(places_ud, i, S[i])
      end

      copy_the_last(places_lr, i)

      places_ud[i].uniq!
    when DOWN
      case T[i]
      when UP
        move_opposite_direction(places_ud, i, S[i])
      when DOWN
        move_same_direction(places_ud, i, S[i])
      when LEFT
        first_move_only(places_ud, i, S[i])
      when RIGHT
        first_move_only(places_ud, i, S[i])
      end

      copy_the_last(places_lr, i)

      places_ud[i].uniq!
    when LEFT
      case T[i]
      when UP
        # 対象位置 + 対象右位置を追加
        first_move_only(places_lr, i, S[i])
      when DOWN
        # 対象位置 + 対象右位置を追加
        first_move_only(places_lr, i, S[i])
      when LEFT
        # 対象左位置が負け位置でない場合
        #   -> なにもしない
        # 対象左位置が負け位置な場合
        #   -> 対象右位置を追加
        # 対象左位置が移動不可の場合
        #   -> 対象位置 + 対象右を追加
        move_same_direction(places_lr, i, S[i])
      when RIGHT
        # 対象左も右も負け位置でない
        #   -> なにもしない
        # 対象左 or 右が負け位置
        #   -> 対象位置を追加
        # 対象右が移動不可
        #   -> 対象位置を追加
        # 対象左が移動不可
        #   -> なにもしない
        move_opposite_direction(places_lr, i, S[i])
      end

      copy_the_last(places_ud, i)

      places_lr[i].uniq!
    when RIGHT
      case T[i]
      when UP
        first_move_only(places_lr, i, S[i])
      when DOWN
        first_move_only(places_lr, i, S[i])
      when LEFT
        move_opposite_direction(places_lr, i, S[i])
      when RIGHT
        move_same_direction(places_lr, i, S[i])
      end

      copy_the_last(places_ud, i)

      places_lr[i].uniq!
    end
  end

  if places_ud[0].include? Sr or places_lr[0].include? Sc
    puts 'NO'
  else
    puts 'YES'
  end
end