P27627 [洛谷] [Language Monthly Contest 202407] Accomplishment
普及
题目描述

Problem Background

For a country, food security is of utmost importance. Therefore, Xiao A believes that the best way to verify this is to count the amount of food.

Problem Description

Xiao A opens the kingdom's map, which can be considered as a grid of $n$ rows and $m$ columns, with each cell representing a city.

In theory, Xiao A only needs to sum up the food counts of each city. However, Xiao A discovers a significant error in his statistics: the food count for each city is not just the food count of that city, but the sum of the food counts of all adjacent cities.

Adjacency here refers to eight-connectivity, meaning that the food count of a city includes its own food count and the food counts of its top, bottom, left, right, top-left, bottom-left, top-right, and bottom-right neighbors:

Given the incorrect results from Xiao A's statistics, please help him calculate the actual total amount of food in his country.

Input Format

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

The next $n$ lines, each containing $m$ integers, represent the food counts displayed on Xiao A's map.

Output Format

A single line containing an integer, representing the true total amount of food in Xiao A's country.

Sample Input and Output

Sample Input #1

3 3
8 12 8 
12 18 13 
9 12 8

Sample Output #1

18

Sample Input #2

3 3
12 18 12
18 27 18
12 18 12

Sample Output #2

27

Sample Input #3

3 6
18 30 27 24 21 16
27 45 45 45 45 33
24 39 36 33 30 22

Sample Output #3

90

Notes

Sample 1 Explanation

One possible set of food counts for Xiao A's kingdom is:
| 1 | 2 | 3 |
| :----------: | :----------: | :----------: |
| 3 | 2 | 1 |
| 1 | 3 | 2 |

It is easy to see that the total sum of food is $18$.

Sample 2 Explanation

One possible set of food counts for Xiao A's kingdom is:
| 3 | 3 | 3 |
| :----------: | :----------: | :----------: |
| 3 | 3 | 3 |
| 3 | 3 | 3 |

It is easy to see that the total sum of food is $27$.

Sample 3 Explanation

One possible set of food counts for Xiao A's kingdom is:
| 1 | 2 | 3 | 4 | 5 | 6 |
| -----------: | -----------: | -----------: | -----------: | -----------: | -----------: |
| 7 | 8 | 9 | 1 | 2 | 3 |
| 4 | 5 | 6 | 7 | 8 | 9 |

It is easy to see that the total sum of food is $90$.

Data Range

  • For $10\%$ of the data, $n, m \le 3$, $a_{i,j} \le 18$.
  • For another $30\%$ of the data, $a_{i,j} \le 9$.
  • For $100\%$ of the data, $1 \le n, m \le 1000$, $1 \le a_{i,j} \le 10^9$, $n, m$ are multiples of $3$. It is guaranteed that the input data corresponds to at least one valid set of actual food data, and each position in this set has food.

Friendly reminder: Take your time, don't rush.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 8 12 8 12 18 13 9 12 8
样例输出
18