Under construction

Still being built. Things may change

Telescope

Time limit1sMemory limit512 MB

Summary
Count the horizontal shifts of an m by l weight grid over an m by n path where the weighted sum exceeds W.
Level

Medium4 of 10

Topics
Sliding window, Prefix sum, Matrix, Implementation
Solved
No attempts yet

Problem

ICPC (Interstellar Cosmology Progress Corporation) is building a new telescope. It picks up optical signals with an m×lm \times l grid of sensors. Each sensor measures the color and the intensity of the light that reaches it. The device filters out noise and then multiplies the intensity by a constant. All the light the sensors collect is merged onto one rectangular film. ICPC expects the telescope to beat current optical and radar telescopes because the usual noise is gone.

An engineer found a flaw in the design. The film withstands light with intensity up to WW. Exposed to light with intensity greater than WW, the telescope may break down.

Here is what happens in practice.

  1. The telescope points at one spot in the sky and moves to the right as time passes, so it scans the sky from left to right.
  2. The telescope is an m×lm \times l grid. The sensor at cell (i,j)(i, j) of the telescope (1≤i≤m1 \le i \le m, 1≤j≤l1 \le j \le l) amplifies the light it receives by P(i,j)P(i, j), where 0≤P(i,j)≤1000 \le P(i, j) \le 100.
  3. The path the telescope scans in the sky is an m×nm \times n grid. T(i,j)T(i, j) is the intensity of light at cell (i,j)(i, j) of the path (1≤i≤m1 \le i \le m, 1≤j≤n1 \le j \le n).
  4. At the start the telescope sits at position 1: the sensor at cell (i,j)(i, j) of the telescope (1≤i≤m1 \le i \le m, 1≤j≤l1 \le j \le l) is aligned with cell (i,j)(i, j) of the path. Each covered cell of the path is covered by exactly one cell of the telescope.
  5. After kk minutes the telescope is at position k+1k + 1: the sensor at cell (i,j)(i, j) of the telescope is aligned with cell (i,j+k)(i, j + k) of the path.
  6. The intensity of light at position k+1k + 1 is Wk=∑i=1m∑j=1lT(i,j+k) P(i,j)W_k = \sum_{i=1}^{m} \sum_{j=1}^{l} T(i, j + k) \, P(i, j). If Wk>WW_k > W, the telescope may break down. The last position of the telescope is n−l+1n - l + 1.

Look at the example below. The path is a 3×53 \times 5 grid, the telescope is a 3×33 \times 3 grid, and W=20W = 20. Each T(i,j)T(i, j) is written at the upper left of its cell and each P(i,j)P(i, j) at the lower right. At position 1 the intensity of light is 1×1+4×1+11×1=16<W1 \times 1 + 4 \times 1 + 11 \times 1 = 16 < W. At position 2 it is 3×1+3×1+3×1=9<W3 \times 1 + 3 \times 1 + 3 \times 1 = 9 < W. At position 3 it stays below WW as well.

Telescope scanning the path

Figure L.1: A telescope moving along the path from left to right. On the left the telescope is at position 1. On the right it has moved to position 2.

Given the sky and the telescope, count how many times the telescope receives light with intensity greater than WW.

Input

The first line contains four integers nn, ll, mm, and WW (l≤n≤10,000l \le n \le 10{,}000, 2≤l≤3,0002 \le l \le 3{,}000, 2≤m≤1002 \le m \le 100, 0≤W≤104×l×m0 \le W \le 10^4 \times l \times m). Here nn is the number of columns of the path, ll is the number of columns of the telescope, mm is the number of rows of both, and WW is the threshold described above.

Each of the next mm lines holds one row of the path. Line i+1i + 1 contains T(i,1),T(i,2),…,T(i,n)T(i, 1), T(i, 2), \ldots, T(i, n) separated by spaces, with 0≤T(i,j)≤1000 \le T(i, j) \le 100.

Each of the next mm lines holds one row of the sensors. Line i+m+1i + m + 1 contains P(i,1),P(i,2),…,P(i,l)P(i, 1), P(i, 2), \ldots, P(i, l) separated by spaces, with 0≤P(i,j)≤1000 \le P(i, j) \le 100.

Output

Print exactly one line holding the number of positions at which the intensity of light on the film is greater than WW. The comparison is strict, so a position whose intensity equals WW is not counted.

Examples3

  1. Example 1

    Input
    4 2 2 40
    1 2 3 4
    1 0 0 0
    10 10
    10 10
    
    Expected output
    2
    
  2. Example 2

    Input
    5 3 2 20
    1 3 5 7 9
    2 4 3 5 2
    1 0 0
    0 1 0
    
    Expected output
    0
    
  3. Example 3

    Input
    2 2 2 4
    1 1
    1 1
    1 1
    1 1
    
    Expected output
    0