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 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<stdio.h>

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

int main(){
	int h,w,n,sx,sy,i,j;
	char s[200000],t[200000];
	scanf("%d%d%d%d%d",&h,&w,&n,&sy,&sx);
	scanf("%s%s",s,t);
	int sl[200000]={0};
	int sr[200000]={0};
	int su[200000]={0};
	int sd[200000]={0};
	int tl[200000]={0};
	int tr[200000]={0};
	int tu[200000]={0};
	int td[200000]={0};
	int f=0;
	for(i=0;i<n;i++){
		if(i>0){
			sl[i]=sl[i-1];
			sr[i]=sr[i-1];
			su[i]=su[i-1];
			sd[i]=sd[i-1];
			tl[i]=tl[i-1];
			tr[i]=tr[i-1];
			tu[i]=tu[i-1];
			td[i]=td[i-1];
		}
		if(s[i]=='L')sl[i]++;
		if(s[i]=='R')sr[i]++;
		if(s[i]=='U')su[i]++;
		if(s[i]=='D')sd[i]++;
		if(sx-sl[i]+tr[i]<1)f=1;
		if(sx+sr[i]-tl[i]>w)f=1;
		if(sy+sd[i]-tu[i]>h)f=1;
		if(sy-su[i]+td[i]<1)f=1;
	//	printf("%d\n",sy-su[i]+td[i]);
		if(t[i]=='L'&&sx+tl[i]+1<=w)tl[i]++;
		if(t[i]=='R'&&sx-tr[i]-1>0)tr[i]++;
		if(t[i]=='U'&&sy-tu[i]-1>0)tu[i]++;
		if(t[i]=='D'&&sy+td[i]+1<=h)td[i]++;
	}
	/*int txr=0,tnr=0,txu=0,tnu=0;
	int f=0;
	for(i=0;i<n;i++){
		if(i>0){
			slr[i]=slr[i-1];
			sud[i]=sud[i-1];
			tlr[i]=tlr[i-1];
			tud[i]=tud[i-1];
		}
		if(s[i]=='L')slr[i]--;
		if(s[i]=='R')slr[i]++;
		if(s[i]=='U')sud[i]--;
		if(s[i]=='D')sud[i]++;
		if(sx+slr[i]+tnr>=w)f=1;
		if(sx+slr[i]+txr<1)f=1;
		if(sy+sud[i]+tnu>=h)f=1;
		if(sy+sud[i]+txu<1)f=1;
		printf("%d\n",sy+sud[i]+txu);
		if(t[i]=='L')tlr[i]--;
		if(t[i]=='R')tlr[i]++;
		if(t[i]=='U')tud[i]--;
		if(t[i]=='D')tud[i]++;
		txr=max(txr,tlr[i]);
		tnr=min(tnr,tlr[i]);
		txu=max(txu,tud[i]);
		tnu=min(tnu,tud[i]);
	}*/
/*	int f=0,maxr=slr[0],minr=slr[0],maxu=sud[0],minu=sud[0];
	for(i=0;i<n;i++)maxr=max(maxr,slr[i]);
	for(i=0;i<n;i++)minr=min(minr,slr[i]);
	for(i=0;i<n;i++)maxu=max(maxu,sud[i]);
	for(i=0;i<n;i++)minu=min(minu,sud[i]);
	int r=maxr+tnr;
	int l=minr+txr;
	int u=maxu+tnu;
	int d=minu+txu;
	if(r+sx>=w)f=1;
	if(l+sx<=0)f=1;
	if(u+sy<=0)f=1;
	if(d+sy>=h)f=1;*/
	if(f==1)puts("NO");
	else puts("YES");
	return 0;
}