#D11814. Bombing
Bombing
Bombing
Problem Statement
JAG land is a country, which is represented as an grid. Its top-left cell is and its bottom-right cell is .
Suddenly, a bomber invaded JAG land and dropped bombs to the country. Its bombing pattern is always fixed and represented by an grid. Each symbol in the bombing pattern is either X
or .
. The meaning of each symbol is as follows.
X
: Bomb.
: Empty
Here, suppose that a bomber is in in the land and drops a bomb. The cell will be damaged if the symbol in the -th row and the -th column of the bombing pattern is X
().
Initially, the bomber reached in JAG land. The bomber repeated to move to either of -directions and then dropped a bomb just times. During this attack, the values of the coordinates of the bomber were between and , inclusive, while it dropped bombs. Finally, the bomber left the country.
The moving pattern of the bomber is described as characters. The -th character corresponds to the -th move and the meaning of each character is as follows.
U
: UpD
: DownL
: LeftR
: Right
Your task is to write a program to analyze the damage situation in JAG land. To investigate damage overview in the land, calculate the number of cells which were damaged by the bomber at least times.
Input
The input consists of a single test case in the format below.
The first line contains four integers , , and (, ). The following lines represent the bombing pattern. is a string of length . Each character of is either X
or .
. The last line denotes the moving pattern. is a string of length , which consists of either U
, D
, L
or R
. It's guaranteed that the values of the coordinates of the bomber are between and , inclusive, while it drops bombs in the country.
Output
Print the number of cells which were damaged by the bomber at least times.
Examples
Input | Output |
---|
2 3 2 4 XX X. RDLU
|
3
7 8 3 5 .XXX.X. X..X.X. ...XX.X XX.XXXX ..XXXX. X.X.... ..XXXXX DRULD
|
26
Example
Input
Output
inputFormat
Input
The input consists of a single test case in the format below.
The first line contains four integers , , and (, ). The following lines represent the bombing pattern. is a string of length . Each character of is either X
or .
. The last line denotes the moving pattern. is a string of length , which consists of either U
, D
, L
or R
. It's guaranteed that the values of the coordinates of the bomber are between and , inclusive, while it drops bombs in the country.
outputFormat
Output
Print the number of cells which were damaged by the bomber at least times.
Examples
Input | Output |
---|
2 3 2 4 XX X. RDLU
|
3
7 8 3 5 .XXX.X. X..X.X. ...XX.X XX.XXXX ..XXXX. X.X.... ..XXXXX DRULD
|
26
Example
Input
Output
样例