This page is still under construction.

Parts of this page are still being built. What you see may change.

Bombing

Time limit2sMemory limit512 MB

Summary
Given a fixed N by N bomb pattern and a walk of L moves, count grid cells damaged at least K times by the repeated bombings.
Level

Medium7 of 10

Topics
Prefix sum, Implementation, Matrix, Brute force
Solved
No attempts yet

Problem

JAG land is a country represented as an M×MM \times M grid. Its top-left cell is (1,1)(1,1) and its bottom-right cell is (M,M)(M,M).

Suddenly, a bomber invaded JAG land and dropped bombs on the country. Its bombing pattern is always fixed and is represented by an N×NN \times N grid. Each symbol in the bombing pattern is either 'X' (bomb) or '.' (empty).

Suppose the bomber is at (br,bc)(b_r,b_c) in the land and drops a bomb. The cell (br+i−1,bc+j−1)(b_r+i-1,b_c+j-1) is damaged if the symbol in the ii-th row and the jj-th column of the bombing pattern is 'X' (1≤i,j≤N1 \le i,j \le N).

Initially, the bomber arrived at (1,1)(1,1) in JAG land. The bomber repeated moving in one of 4 directions and then dropping a bomb exactly LL times. During this attack, the values of the bomber's coordinates were between 1 and M−N+1M-N+1, inclusive, whenever it dropped bombs. Finally, the bomber left the country.

The bomber's movement pattern is given as LL characters. The ii-th character corresponds to the ii-th move and the meaning of each character is as follows.

'U' is up, 'D' is down, 'L' is left, and 'R' is right.

Your task is to write a program that analyzes the damage situation in JAG land. To investigate the damage overview in the land, calculate the number of cells that were damaged by the bomber at least KK times.

Input

The first line of the input contains four integers NN, MM, KK, and LL (1≤N≤M≤5001 \le N \le M \le 500, 1≤K≤L≤2⋅1051 \le K \le L \le 2 \cdot 10^5). The following NN lines represent the bombing pattern. BiB_i is a string of length NN. Each character of BiB_i is either 'X' or '.'. The last line is the movement pattern. SS is a string of length LL consisting of 'U', 'D', 'L', or 'R'. It is guaranteed that the values of the bomber's coordinates are between 1 and M−N+1M-N+1, inclusive, whenever it drops bombs in the country.

Output

Print the number of cells that were damaged by the bomber at least KK times.

Examples2

  1. Example 1

    Input
    2 3 2 4
    XX
    X.
    RDLU
    
    Expected output
    3
    
  2. Example 2

    Input
    8 10 1 3
    XXX.XX..
    .XX...X.
    XX.XXXXX
    ........
    XXX.X..X
    .X.XX..X
    ..X.X.X.
    X.XX..X.
    RRD
    
    Expected output
    63