P9582 "MXOI Round 1" Grid

Description

Xiao C and the grid are good friends. Xiao C has a grid with $n$ rows and $m$ columns. Each cell contains a number, and the number in the cell at row $i$ and column $j$ is $a_{i,j}$. We define that, in this grid, two different cells are non-adjacent if and only if these two cells **do not share a common edge**. Xiao C thinks that two different cells are good friends of each other if and only if these two cells are **non-adjacent** and **the numbers in these two cells are the same**. Xiao C wants you to help compute the total sum of the number of good friends over all cells.

Input Format

The first line contains two integers $n,m$. The next $n$ lines each contain $m$ integers, where the $j$-th integer in the $i$-th line represents $a_{i,j}$.

Output Format

Output one integer, representing the total sum of the number of good friends over all cells.

Explanation/Hint

#### Sample Explanation #1 The cell in row $1$ column $1$ has $3$ good friends, the cell in row $1$ column $2$ has $2$ good friends, the cell in row $1$ column $3$ has $1$ good friend, and the cell in row $1$ column $4$ has $0$ good friends. The cell in row $2$ column $1$ has $1$ good friend, the cell in row $2$ column $2$ has $2$ good friends, the cell in row $2$ column $3$ has $1$ good friend, and the cell in row $2$ column $4$ has $1$ good friend. The cell in row $3$ column $1$ has $1$ good friend, the cell in row $3$ column $2$ has $3$ good friends, the cell in row $3$ column $3$ has $1$ good friend, and the cell in row $3$ column $4$ has $4$ good friends. The total sum of the number of good friends over all cells is $20$. #### Sample #2 See `square/square2.in` and `square/square2.ans` in the additional files. This sample satisfies the constraints of test point $1$. #### Sample #3 See `square/square3.in` and `square/square3.ans` in the additional files. This sample satisfies the constraints of test point $4$. #### Sample #4 See `square/square4.in` and `square/square4.ans` in the additional files. This sample satisfies the constraints of test point $6$. #### Sample #5 See `square/square5.in` and `square/square5.ans` in the additional files. This sample satisfies the constraints of test point $10$. #### Constraints For $100\%$ of the testdata, $1 \le n,m \le 2000$, and $1 \le a_{i,j} \le 9$. |Test Point|$n,m \le$|$a_{i,j} \le$|Special Property| |:---:|:---:|:---:|:---:| |$1\sim3$|$80$|$9$|No| |$4\sim5$|$2000$|$1$|No| |$6\sim7$|$2000$|$9$|Yes| |$8\sim10$|$2000$|$9$|No| Special property: It is guaranteed that the numbers in any two adjacent cells are different. Translated by ChatGPT 5