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 Rust (1.15.1) (judge verdict: Accepted)

use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (h, w, _n) = i.read3::<usize, usize, usize>();
    let (y, x) = i.read2::<usize, usize>();
    let s: Vec<_> = i.read_line_bytes_vec();
    let t: Vec<_> = i.read_line_bytes_vec();

    let ans = if solve(y - 1, x - 1, h, w, &s, &t) {
        "YES"
    } else {
        "NO"
    };
    writeln!(o, "{}", ans).unwrap();
}
fn solve(y: usize, x: usize, h: usize, w: usize, s: &[u8], t: &[u8]) -> bool {
    let mut rx0 = 0;
    let mut rx1 = 0;
    let mut ry0 = 0;
    let mut ry1 = 0;
    for (&s, &t) in s.iter().zip(t).rev() {
        if rx0 + rx1 == w {
            return false;
        }
        if ry0 + ry1 == h {
            return false;
        }
        match t {
            b'L' => {
                if rx1 > 0 {
                    rx1 -= 1;
                }
            }
            b'R' => {
                if rx0 > 0 {
                    rx0 -= 1;
                }
            }
            b'U' => {
                if ry1 > 0 {
                    ry1 -= 1;
                }
            }
            b'D' => {
                if ry0 > 0 {
                    ry0 -= 1;
                }
            }
            _ => unreachable!(),
        }
        match s {
            b'L' => rx0 += 1,
            b'R' => rx1 += 1,
            b'U' => ry0 += 1,
            b'D' => ry1 += 1,
            _ => unreachable!(),
        }
    }
    !(rx0 >= x + 1 || ry0 >= y + 1 || rx1 >= w - x || ry1 >= h - y)
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
        b: Vec<u8>,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
                b: Vec::new(),
            }
        }

        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.b.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        #[allow(dead_code)]
        pub fn read_line_bytes(&mut self) -> &[u8] {
            self.s.clear();
            self.b.clear();
            self.r.read_until(b'\n', &mut self.b).unwrap();
            if self.b.last() == Some(&b'\n') {
                self.b.pop();
            }
            &self.b
        }
        pub fn read_line_bytes_vec(&mut self) -> Vec<u8> {
            let mut b = Vec::new();
            self.r.read_until(b'\n', &mut b).unwrap();
            if b.last() == Some(&b'\n') {
                b.pop();
            }
            b
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}