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: Accepted)

using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            AGC033.B();
        }

        class AGC033
        {
            public static void A()
            {
                var H = Read.Int();
                var W = Read.Int();
                var A = new bool[H + 2, W + 2];
                Queue<Tuple<int, int>> queue = new Queue<Tuple<int, int>>();
                for(int i = 1; i <= H; ++i)
                {
                    var str = Read.Str();
                    for (int j = 0; j < W; ++j)
                    {
                        A[i, j + 1] = str[j] == '.';
                        if (str[j] == '#')
                        {
                            queue.Enqueue(new Tuple<int, int>(i, j + 1));
                        }
                    }
                }
                var distMax = 0;
                var dist = new int[H + 2, W + 2];
                for(int i = 0; i < H + 2; ++i)
                {
                    for(int j = 0; j < W + 2; ++j)
                    {
                        dist[i, j] = A[i, j] ? -1 : 0;
                    }
                }
                var dx = new int[] { 1, 0, -1, 0 };
                var dy = new int[] { 0, 1, 0, -1 };
                while (queue.Count > 0)
                {
                    var t = queue.Dequeue();
                    for(int i = 0; i < 4; ++i)
                    {
                        var x = t.Item1 + dx[i];
                        var y = t.Item2 + dy[i];
                        if (dist[x, y] < 0)
                        {
                            dist[x, y] = dist[t.Item1, t.Item2] + 1;
                            distMax = Math.Max(distMax, dist[x, y]);
                            queue.Enqueue(new Tuple<int, int>(x, y));
                        }
                    }
                }
                Console.WriteLine(distMax);
            }
            public static void B()
            {
                var H = Read.Int();
                var W = Read.Int();
                var N = Read.Int();
                var SR = Read.Int();
                var SC = Read.Int();
                var S = Read.Str();
                var T = Read.Str();
                {
                    int idx1 = 0;
                    int idx2 = H;
                    for(int i = N - 1; i >= 0; --i)
                    {
                        switch (T[i])
                        {
                            case 'U': idx2 = Math.Min(H, idx2 + 1); break;
                            case 'D': idx1 = Math.Max(0, idx1 - 1); break;
                        }
                        switch (S[i])
                        {
                            case 'U': idx1++; break;
                            case 'D': idx2--; break;
                        }
                        if (idx1 == idx2) { Console.WriteLine("NO"); return; }
                    }
                    if(idx1>=SR || idx2 < SR) { Console.WriteLine("NO"); return; }
                }
                {
                    int idx1 = 0;
                    int idx2 = W;
                    for (int i = N - 1; i >= 0; --i)
                    {
                        switch (T[i])
                        {
                            case 'L': idx2 = Math.Min(W, idx2 + 1); break;
                            case 'R': idx1 = Math.Max(0, idx1 - 1); break;
                        }
                        switch (S[i])
                        {
                            case 'L': idx1++; break;
                            case 'R': idx2--; break;
                        }
                        if (idx1 == idx2) { Console.WriteLine("NO"); return; }
                    }
                    if (idx1 >= SC || idx2 < SC) { Console.WriteLine("NO"); return; }
                }
                Console.WriteLine("YES");
            }
            public static void C()
            {
                var N = Read.Int();
                var Adj = Read.AdjacencyList(N, N - 1);
                var dist1 = Util.CalcDistance_OnTree(Adj, N, 1);
                var max = dist1.Max();
                var dist2 = Util.CalcDistance_OnTree(Adj, N, Enumerable.Range(1, N).Where(i => dist1[i] == max).First());
                var d = dist2.Max();
                Console.WriteLine(d % 3 != 1 ? "First" : "Second");
            }
        }


        class Util
        {
            public static int[] CalcDistance_OnTree(Dictionary<int, HashSet<int>> adj, int N, int start)
            {
                var dist = Enumerable.Range(0, N + 1).Select(i => -1).ToArray();
                dist[start] = 0;
                Queue<int> queue = new Queue<int>();
                queue.Enqueue(start);
                while (queue.Count > 0)
                {
                    var v = queue.Dequeue();
                    foreach (var w in adj[v])
                    {
                        if (dist[w] < 0)
                        {
                            dist[w] = dist[v] + 1;
                            queue.Enqueue(w);
                        }
                    }
                }
                return dist;
            }
        }

        static class Read
        {
            static Queue<string> queue = new Queue<string>();
            static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
            public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
            public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
            public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
            public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
            public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
            public static string[] StrN() { return Console.ReadLine().Split(' '); }
            public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
            public static long[,] LongMatrix(int r, int c)
            {
                var mat = new long[r, c];
                for (int i = 0; i < r; ++i)
                {
                    var x = Read.LongN();
                    for (int j = 0; j < c; ++j)
                    {
                        mat[i, j] = x[j];
                    }
                }
                return mat;
            }
            public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M)
            {
                Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new HashSet<int>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1]);
                    dict[ab[1]].Add(ab[0]);
                }
                return dict;
            }
            public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M)
            {
                Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new Dictionary<int, long>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1], ab[2]);
                    dict[ab[1]].Add(ab[0], ab[2]);
                }
                return dict;
            }
        }
    }
}