Telescope
Time limit1sMemory limit512 MB
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 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 . Exposed to light with intensity greater than , the telescope may break down.
Here is what happens in practice.
- 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.
- The telescope is an grid. The sensor at cell of the telescope (, ) amplifies the light it receives by , where .
- The path the telescope scans in the sky is an grid. is the intensity of light at cell of the path (, ).
- At the start the telescope sits at position 1: the sensor at cell of the telescope (, ) is aligned with cell of the path. Each covered cell of the path is covered by exactly one cell of the telescope.
- After minutes the telescope is at position : the sensor at cell of the telescope is aligned with cell of the path.
- The intensity of light at position is . If , the telescope may break down. The last position of the telescope is .
Look at the example below. The path is a grid, the telescope is a grid, and . Each is written at the upper left of its cell and each at the lower right. At position 1 the intensity of light is . At position 2 it is . At position 3 it stays below as well.

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 .
Input
The first line contains four integers , , , and (, , , ). Here is the number of columns of the path, is the number of columns of the telescope, is the number of rows of both, and is the threshold described above.
Each of the next lines holds one row of the path. Line contains separated by spaces, with .
Each of the next lines holds one row of the sensors. Line contains separated by spaces, with .
Output
Print exactly one line holding the number of positions at which the intensity of light on the film is greater than . The comparison is strict, so a position whose intensity equals is not counted.