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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        int[] hwn = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int H = hwn[0];
        int W = hwn[1];
        int N = hwn[2];

        int[] rc = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int sr = rc[0];
        int sc = rc[1];

        string S = Console.ReadLine();
        string T = Console.ReadLine();

        bool isRemain = true;

        //横方向判定
        {
            int rangeSt = 1;
            int rangeEd = W;

            for (int i = S.Length - 1; i >= 0; i--)
            {
                char chT = T[i];
                char chS = S[i];

                //後手の補正
                if (chT == 'R')
                {
                    //この後手を指す直前に居ても大丈夫な範囲が左側に1増える
                    rangeSt = Math.Max(rangeSt - 1, 1);                    
                }
                else if (chT == 'L')
                {
                    //この後手を指す直前に居ても大丈夫な範囲が右側に1増える
                    rangeEd = Math.Min(rangeEd + 1, W);
                }

                //後手が始まる前にいても良い範囲がない時点で後手の負けは確定
                if (rangeEd == rangeSt)
                {
                    isRemain = false;
                }

                //先手の補正
                if (chS == 'R')
                {
                    //この先手を指す直前に居ても大丈夫な範囲が右側から1縮む
                    rangeEd--;
                }
                else if (chS == 'L')
                {
                    //この先手を指す直前にいても大丈夫な範囲が左側から1縮む
                    rangeSt++;
                }

                //先手が始まる前にいても良い範囲がない時点で後手の負けは確定
                if (rangeEd == rangeSt)
                {
                    isRemain = false;
                }
            }

            //更に初期座標が居ても良い範囲に含まれていない場合、後手の負けが確定
            if (rangeSt > sc || sc > rangeEd)
            {
                isRemain = false;
            }
        }

        //縦方向判定
        {
            int rangeSt = 1;
            int rangeEd = H;

            for (int i = S.Length - 1; i >= 0; i--)
            {
                char chT = T[i];
                char chS = S[i];

                //後手の補正
                if (chT == 'D')
                {
                    //この後手を指す直前に居ても大丈夫な範囲が上側に1増える
                    rangeSt = Math.Max(rangeSt - 1, 1);
                }
                else if (chT == 'U')
                {
                    //この後手を指す直前に居ても大丈夫な範囲が下側に1増える
                    rangeEd = Math.Min(rangeEd + 1, H);
                }

                //後手が始まる前にいても良い範囲がない時点で後手の負けは確定
                if (rangeEd == rangeSt)
                {
                    isRemain = false;
                }

                //先手の補正
                if (chS == 'D')
                {
                    //この先手を指す直前に居ても大丈夫な範囲が下側から1縮む
                    rangeEd--;
                }
                else if (chS == 'U')
                {
                    //この先手を指す直前にいても大丈夫な範囲が上側から1縮む
                    rangeSt++;
                }

                //先手が始まる前にいても良い範囲がない時点で後手の負けは確定
                if (rangeEd == rangeSt)
                {
                    isRemain = false;
                }
            }

            //更に初期座標が居ても良い範囲に含まれていない場合、後手の負けが確定
            if (rangeSt > sr || sr > rangeEd)
            {
                isRemain = false;
            }
        }

        Console.WriteLine(isRemain ? "YES" : "NO");
    }
}



static class MathUtil
{
    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}