Hide

Problem J
The Big Painting

/problems/bigpainting/file/statement/en/img-0001.jpg
Galerie de Vues de la Rome Moderne, Panini (1759).
What S.W.E.R.C. had in mind when he tried to merge his paintings.

Samuel W. E. R. Craft is an artist with a growing reputation. Unfortunately, the paintings he sells do not provide him enough money for his daily expenses plus the new supplies he needs. He had a brilliant idea yesterday when he ran out of blank canvas: “Why don’t I create a gigantic new painting, made of all the unsellable paintings I have, stitched together?” After a full day of work, his masterpiece was complete.

That’s when he received an unexpected phone call: a client saw a photograph of one of his paintings and is willing to buy it now! He had forgotten to tell the art gallery to remove his old works from the catalog! He would usually welcome a call like this, but how is he going to find his old work in the huge figure in front of him?

Task

Given a black-and-white representation of his original painting and a black-and-white representation of his masterpiece, can you help S.W.E.R.C. identify in how many locations his painting might be?

Input

The first line consists of 4 space-separated integers: $h_ p$ $w_ p$ $h_ m$ $w_ m$, the height and width of the painting he needs to find, and the height and width of his masterpiece, respectively.

The next $h_ p$ lines have $w_ p$ lower-case characters representing his painting. After that, the next $h_ m$ lines have $w_ m$ lower-case characters representing his masterpiece. Each character will be either ‘x’ or ‘o’.

Constraints

$1 \leq h_ p, w_ p \leq 2\, 000$
$1 \leq h_ m, w_ m \leq 2\, 000$
$h_ p \leq h_ m$
$w_ p \leq w_ m$

Output

A single integer representing the number of possible locations where his painting might be.

Sample Output Explanation

The painting could be in four locations as shown in the following picture. Two of the locations overlap.

\includegraphics[width=1.5in]{sample_output_explanation.png}
Sample Input 1 Sample Output 1
4 4 10 10
oxxo
xoox
xoox
oxxo
xxxxxxoxxo
oxxoooxoox
xooxxxxoox
xooxxxoxxo
oxxoxxxxxx
ooooxxxxxx
xxxoxxoxxo
oooxooxoox
oooxooxoox
xxxoxxoxxo
4

Please log in to submit a solution to this problem

Log in