#B4248. Neighboring Cell Count

    ID: 11905 Type: Default 1000ms 256MiB

Neighboring Cell Count

Neighboring Cell Count

Given a grid of $n$ rows and $m$ columns, where the cell in the $i$-th row and $j$-th column contains a positive integer $a_{i,j}$, a cell is considered to be adjacent to another if they share a common edge. For example, cell $(7,2)$ is adjacent to cell $(7,3)$, but not to cell $(8,3)$.

You are given two integers $x$ and $y$. Your task is to count the number of cells in the entire grid that have the value $x$ and have at least one adjacent cell with the value $y$.

inputFormat

The first line contains two integers $n$ and $m$ --- the number of rows and columns of the grid.

Then follow $n$ lines, each containing $m$ positive integers, representing the grid.

The last line contains two integers $x$ and $y$.

outputFormat

Output a single integer --- the count of cells whose value is $x$ and that have at least one adjacent cell with the value $y$.

sample

3 3
1 2 3
4 5 6
7 8 9
5 2
1