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# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            //var N = long.Parse(Console.ReadLine());
            Solve();
            
        }
        static string S;
        static string T;
        static int H;
        static int W;
        static int N;
        static int SH;
        static int SW;
        static void Solve()
        {
            var HWN = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            H = HWN[0];
            W = HWN[1];
            N = HWN[2];
            var SP = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            SH = SP[0];
            SW = SP[1];
            S = Console.ReadLine();
            T = Console.ReadLine();
            var ans = false;
            if (ToR() || ToD() || ToL() || ToU())
            {
                ans = true;
            }
            Console.WriteLine(ans ? "NO" : "YES");
        }

        static bool ToR()
        {
            var now = SW;
            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'R') now++;
                if (W < now) return true;
                if (T[i] == 'L' && now > 1) now--;
            }
            return false;
        }

        static bool ToD()
        {
            var now = SH;
            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'D') now++;
                if (W < now) return true;
                if (T[i] == 'U' && now > 1) now--;
            }
            return false;
        }

        static bool ToL()
        {
            var now = SW;
            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'L') now--;
                if (0 >= now) return true;
                if (T[i] == 'R' && now < W) now++;
            }
            return false;
        }

        static bool ToU()
        {
            var now = SH;
            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'U') now--;
                if (0 >= now) return true;
                if (T[i] == 'D' && now < H) now++;
            }
            return false;
        }
        class Treap<T> : IEnumerable<T> where T : IComparable
        {
            public int Length
            {
                get { return this.Root == null ? 0 : this.NodeCount(this.Root); }
            }
            public T this[int i]
            {
                get
                {
                    if (this.Root.Count < i - 1) throw new IndexOutOfRangeException();
                    return this.Root.Get(i);
                }
            }
            public Node Root;
            private IComparer<T> Cmp = Comparer<T>.Default;
            public Treap(IComparer<T> cmp = null)
            {
                if (cmp != null) this.Cmp = cmp;
            }
            public Node Merge(Node l, Node r)
            {
                if (l == null || r == null) return l == null ? r : l;

                if (l.Priority > r.Priority)
                {
                    l.R = this.Merge(l.R, r);
                    return this.Update(l);
                }
                else
                {
                    r.L = this.Merge(l, r.L);
                    return this.Update(r);
                }
            }
            // 左にk個、右に残り(n-k)個に分割する
            public (Node, Node) Split(int k) { return this.Split(this.Root, k); }
            public (Node, Node) Split(Node t, int k)
            {
                if (t == null) return (null, null);
                if (k <= this.NodeCount(t.L))
                {
                    var s = this.Split(t.L, k);
                    t.L = s.Item2;
                    return (s.Item1, this.Update(t));
                }
                else
                {
                    var s = this.Split(t.R, k - this.NodeCount(t.L) - 1);
                    t.R = s.Item1;
                    return (this.Update(t), s.Item2);
                }
            }
            public int NodeCount(Node node)
            {
                return node == null ? 0 : node.Count;
            }
            public int LowerBouond(T value) { return this.LowerBouond(this.Root, value); }
            public int LowerBouond(Node node, T value)
            {
                if (node == null) return 0;
                if (this.Cmp.Compare(value, node.Value) <= 0)
                    return this.LowerBouond(node.L, value);
                else
                    return this.NodeCount(node.L) + 1 + this.LowerBouond(node.R, value);
            }
            public int UpperBound(T value) { return this.UpperBound(this.Root, value); }
            public int UpperBound(Node node, T value)
            {
                if (node == null) return 0;
                if (this.Cmp.Compare(value, node.Value) >= 0)
                    return this.NodeCount(node.L) + 1 + this.UpperBound(node.R, value);
                else
                    return this.UpperBound(node.L, value);
            }
            public int ValueCount(T value)
            {
                return this.UpperBound(value) - this.LowerBouond(value);
            }
            public void Insert(T value)
            {
                var sub = this.Split(this.Root, this.LowerBouond(value));
                var newNode = new Node(value);
                var merged = this.Merge(sub.Item1, newNode);
                this.Root = this.Merge(merged, sub.Item2);
            }
            public void Erase(T value)
            {
                if (this.ValueCount(value) == 0) return;
                var sub = this.Split(this.Root, this.LowerBouond(value));
                this.Root = this.Merge(sub.Item1, this.Split(sub.Item2, 1).Item2);
            }
            public void InsertAt(Node node, int k)
            {
                var sub = this.Split(this.Root, k);
                var merged = this.Merge(sub.Item1, node);
                this.Root = this.Merge(merged, sub.Item2);
            }
            public void InsertAt(T value, int k)
            {
                var node = new Node(value);
                var sub = this.Split(this.Root, k);
                var merged = this.Merge(sub.Item1, node);
                this.Root = this.Merge(merged, sub.Item2);
            }
            public Node EraseAt(int k)
            {
                var sub = this.Split(this.Root, k);
                var sub2 = this.Split(sub.Item2, 1);
                var res = sub2.Item1;
                this.Root = this.Merge(sub.Item1, sub2.Item2);
                return res;
            }
            public Node Update(Node node)
            {
                node.Count = this.NodeCount(node.L) + this.NodeCount(node.R) + 1;
                return node;
            }
            public class Node
            {
                private static Random Rand = new Random();
                public T Value;
                public Node L = null;
                public Node R = null;
                public int Count;
                public double Priority;
                public Node(T value, double priority)
                {
                    this.Value = value;
                    this.Priority = priority;
                    this.Count = 1;
                }
                public Node(T value) : this(value, Rand.NextDouble()) { }
                public T Get(int i) { return this.GetNode(i).Value; }
                public Node GetNode(int i)
                {
                    var lcount = 0;
                    if (this.L != null) lcount = this.L.Count;
                    if (lcount == i) return this;
                    else if (lcount < i) return this.R.GetNode(i - lcount - 1);
                    else return this.L.GetNode(i);
                }
            }
            public IEnumerator<T> GetEnumerator()
            {
                for (int i = 0; i < this.Length; i++) yield return this.Root.Get(i);
            }
            IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
        }
    }
}