ARHIPELAG
문제
One popular touristic country is situated on a sunny archipelago. Citizens of that country are very proud of their numerous islands. There are so many islands that some of them even have completely equal layout: two islands have equal layout if we can translate one so that his layout completely overlaps with the layout of the second island. This fact delights tourists so much that they decided to measure the beauty of the archipelago as the total number of pairs of islands with identical layouts.
However, global warming has worried the citizens: elevation of the sea level results in the higher loss of the shore, which causes changes in the beauty of the archipelago.
More precisely, the map of the archipelago is shown with R x C squares. In some moment for each square this elevation was measured: elevation is equal to 0 if there was sea on that square when the measurement was taken, else it's equal to some natural number - elevation of that square in meters. The sea level rises for 1 meter every year, and after T years it will flood all the squares which had their elevation smaller or equal to T when they were measured. Considering that the archipelago is rocky and porous in origin, the sea penetrates the inside of the island, flooding all the parts which are not above the sea level. Two ground squares belong to the same island if it's possible to go from one square to the other by doing consecutive moves on the contiguous left, right, lower or top ground square.
| [이미지 1] | [이미지 2] |
| Archipelago in the moment the elevation is measured | Archipelago after 5 years |
Citizens are interested in knowing how the beauty of their archipelago is going to change over the course of a few centuries. Write a program which will, for each of the given years, determine the beauty of the archipelago after that many years pass from the moment of measurement of elevation.
입력
In the first line there are natural numbers R and C (3 ≤ R, C ≤ 1000), dimensions of the map.
In each of the following R lines there are C nonnegative integers divided by space, of value at most 109, which represent elevations of the squares in the moment of measurement.
In the next line there is a natural number Q (1 ≤ Q ≤ 100 000), number of years for which we need to determine the beauty of the archipelago.
In the next line there are Q natural numbers divided by space, of value at most 109, which represent years for which we need to determine the beauty of the archipelago. Years are listed sorted, from less to greater.
출력
You must output a total of Q lines.
In every line output the beauty of the archipelago after the appropriate number of years in the input data, in the same order as listed there.
예제
예제 1
5 6 100 2 3 4 5 6 20 4 45 12 3 4 0 0 1 2 3 0 0 0 0 0 0 0 0 0 1 2 3 0 3 1 4 10
0 1 0
예제 2
7 6 5 8 0 9 7 6 7 0 0 9 2 6 8 0 6 7 9 7 0 0 8 7 0 0 0 5 0 0 3 2 0 9 0 0 6 0 8 1 0 0 7 0 1 5
4