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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
typedef long long int lli;
typedef pair<int, int> P;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int sr, sc;
    cin >> sr >> sc;
    string s, t;
    cin >> s >> t;

    int s_l, s_r, s_u, s_d;
    s_l = count(s.cbegin(), s.cend(), 'L');
    s_r = count(s.cbegin(), s.cend(), 'R');
    s_u = count(s.cbegin(), s.cend(), 'U');
    s_d = count(s.cbegin(), s.cend(), 'D');


    // left_l 個まではいける。
    int left_l, left_r, left_u, left_d;
    left_l = sr - 1;
    left_r = w - sr;
    left_u = sc - 1;
    left_d = h - sc;

    bool l_p, r_p, u_p, d_p;
    l_p = r_p = u_p = d_p = false;
    if (left_l - s_l < 0)
        l_p = true;
    if (left_r - s_r < 0)
        r_p = true;
    if (left_u - s_u < 0)
        u_p = true;
    if (left_u - s_d < 0)
        d_p = true;

    int safe_l = 1;
    int safe_r = w;
    for(int i=n-1; i>=0; i--) {
        if (s[i] == 'R')
            safe_r--;
        else if (s[i] == 'L')
            safe_l++;

        if (safe_r < safe_l) {
            //cout << "lrhoge" << endl;
            cout << "NO" << endl;
            return 0;
        }
        if (i != 0) {
            if (t[i-1] == 'L' && safe_r < w)
                safe_r++;
            else if (t[i-1] == 'R' && safe_l > 1)
                safe_l--;
        }
    }
    if (sc < safe_l || sc > safe_r) {
        //cout << "lrgeho" << endl;
        cout << "NO" << endl;
        return 0;
    }
    int safe_u = 1;
    int safe_d = h;
    for(int i=n-1; i>=0; i--) {
        if (s[i] == 'D')
            safe_d--;
        else if (s[i] == 'U')
            safe_u++;
        if (safe_d < safe_u) {
            //cout << "udhoge" << endl;
            cout << "NO" << endl;
            return 0;
        }
        if (i != 0) {
            if (t[i-1] == 'U' && safe_d < h)
                safe_d++;
            else if (t[i-1] == 'D' && safe_u > 1)
                safe_u--;
        }
    }
    if (sr < safe_u || sr > safe_d) {
        //cout << "udgeho" << endl;
        cout << "NO" << endl;
        return 0;
    }

    //if (r_p) {
    //    cout << "r_p" << endl;
    //    int r = left_r;
    //    for(int i=n-1; i>=0; i--) {
    //        if (s[i] == 'R')
    //            r--;
    //        if (t[i] == 'L')
    //            r++;
    //        if (r < 0) {
    //            cout << "r_p" << endl;
    //            cout << "NO" << endl;
    //            return 0;
    //        }
    //    }
    //}
    //if (l_p) {
    //    cout << "l_p" << endl;
    //    int l = left_l;
    //    for(int i=n-1; i>=0; i--) {
    //        if (s[i] == 'L')
    //            l--;
    //        if (t[i] == 'R')
    //            l++;
    //        if (l < 0) {
    //            cout << "l_p" << endl;
    //            cout << "NO" << endl;
    //            return 0;
    //        }
    //    }
    //}

    //if (u_p) {
    //    cout << "u_p" << endl;
    //    int u = left_u;
    //    for(int i=n-1; i>=0; i--) {
    //        if (s[i] == 'U')
    //            u--;
    //        if (t[i] == 'D')
    //            u++;
    //        if (u < 0) {
    //            cout << "u_p" << endl;
    //            cout << "NO" << endl;
    //            return 0;
    //        }
    //    }
    //}
    //if (d_p) {
    //    cout << "d_p" << endl;
    //    int d = left_d;
    //    for(int i=n-1; i>=0; i--) {
    //        if (s[i] == 'D')
    //            d--;
    //        if (t[i] == 'U')
    //            d++;
    //        if (d < 0) {
    //            cout << "d_p" << endl;
    //            cout << "NO" << endl;
    //            return 0;
    //        }
    //    }
    //}
    //if (r_p) {
    //    int l = left_l;
    //    int r = left_r;
    //    REP(i, n) {
    //        if (s[i] == 'R') {
    //            l++;
    //            r--;;
    //        }
    //        if (r < 0) {
    //            cout << "NO" << endl;
    //            return 0;
    //        }
    //        if (t[i] == 'L'){
    //            if (l > 0) {
    //                l--;
    //                r++;
    //            }
    //        }
    //    }
    //}
    //if (l_p) {
    //    int l = left_l;
    //    int r = left_r;
    //    REP(i, n) {
    //        if (s[i] == 'L') {
    //            r++;
    //            l--;;
    //        }
    //        if (l < 0) {
    //            cout << "NO" << endl;
    //            return 0;
    //        }
    //        if (t[i] == 'R'){
    //            if (r > 0) {
    //                r--;
    //                l++;
    //            }
    //        }
    //    }
    //}
    //// r->u
    //if (u_p) {
    //    int d = left_d;
    //    int u = left_u;
    //    REP(i, n) {
    //        if (s[i] == 'U') {
    //            d++;
    //            u--;;
    //        }
    //        if (u < 0) {
    //            cout << "NO" << endl;
    //            return 0;
    //        }
    //        if (t[i] == 'D'){
    //            if (d > 0) {
    //                d--;
    //                u++;
    //            }
    //        }
    //    }
    //}
    //if (d_p) {
    //    int d = left_d;
    //    int u = left_u;
    //    REP(i, n) {
    //        if (s[i] == 'D') {
    //            u++;
    //            d--;;
    //        }
    //        if (d < 0) {
    //            cout << "NO" << endl;
    //            return 0;
    //        }
    //        if (t[i] == 'U'){
    //            if (u > 0) {
    //                left_u--;
    //                d++;
    //            }
    //        }
    //    }
    //}

    cout << "YES" << endl;
}