QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100

#16568. Grid

統計

Xiao C and the grid are good friends.

Xiao C has a grid with $n$ rows and $m$ columns, where each cell contains a number. The number in the cell at row $i$ and column $j$ is $a_{i,j}$.

We define that two distinct cells are not adjacent if and only if they do not share a common edge.

Xiao C considers two distinct cells to be "good friends" if and only if they are not adjacent and the numbers in these two cells are the same.

Xiao C wants you to help calculate the sum of the number of good friends for all cells in the grid.

Input

The first line contains two integers $n$ and $m$.

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

Output

A single integer representing the sum of the number of good friends for all cells.

Examples

Input 1

3 4
1 1 4 5
2 1 2 3
3 1 4 1

Output 1

20

Note 1

The cell at row $1$, column $1$ has $3$ good friends; the cell at row $1$, column $2$ has $2$ good friends; the cell at row $1$, column $3$ has $1$ good friend; the cell at row $1$, column $4$ has $0$ good friends.

The cell at row $2$, column $1$ has $1$ good friend; the cell at row $2$, column $2$ has $2$ good friends; the cell at row $2$, column $3$ has $1$ good friend; the cell at row $2$, column $4$ has $1$ good friend.

The cell at row $3$, column $1$ has $1$ good friend; the cell at row $3$, column $2$ has $3$ good friends; the cell at row $3$, column $3$ has $1$ good friend; the cell at row $3$, column $4$ has $4$ good friends.

The sum of the number of good friends for all cells is $20$.

Examples 2-5

See the files square/square2.in through square/square5.in and their corresponding .ans files in the additional files. These examples satisfy the constraints of test cases $1, 4, 6,$ and $10$ respectively.

Constraints

For $100\%$ of the data, $1 \le n, m \le 2000$, $1 \le a_{i,j} \le 9$.

Test Case ID $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 any two adjacent cells contain different numbers.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.