QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 1024 MB Points totaux : 100

#17966. Domino Game

Statistiques

There is a grid of size $N \times M$. The cell at row $i$, column $j$ contains a non-negative integer $a_{ij}$. ($1 \le i \le N$; $1 \le j \le M$)

Each turn, Minji performs the following actions.

  1. Minji selects two horizontally or vertically adjacent grid cells. At least one of the two cells must contain a positive integer.
  2. Minji decreases the number in each selected cell by $1$. However, if some cell contains $0$, she does not decrease that number.

The game ends when every cell contains $0$. Minji wishes to play this game as long as she can. Find out the maximum number of turns the game can last when Minji does her best.

Input

The first line of input contains two space-separated positive integers $N$ and $M$. ($2 \le N, M \le 1\,000$)

Then, $N$ lines follow. The $i$-th of them contains $M$ space-separated integers $a_{i1}, a_{i2}, \cdots, a_{iM}$. ($0 \le a_{ij} \le 10^9$)

Output

In the first line, print the maximum number of turns the game can last.

Examples

Input 1

2 2
0 1
0 0

Output 1

1

Input 2

2 2
1 0
1 1

Output 2

3

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.