#P6559. [SBCOI2020] 小镇

[SBCOI2020] 小镇

Description

The town can be viewed as an n×nn \times n grid, where kk cells are houses.
There are also lamps in the town. Between every two adjacent cells, there is a lamp.

If two houses are adjacent, then the lamp between these two houses will be lit.
Please find how many lamps are lit in total in this town.

Note: in this problem, “adjacent” means sharing a common edge.

Input Format

The first line contains two integers n,kn, k, representing the side length of the grid and the number of houses.
The next kk lines each contain two integers x,yx, y, representing the coordinates of a house.

Output Format

One line with one integer, representing the answer.

6 12
1 1
2 1
2 2
1 4
3 3
4 3
4 4
3 4
3 6
4 6
5 6
6 6
9

Hint

Sample Explanation


As shown in the figure, the shaded cells are houses, and the red edges are lamps.

Constraints

For 30%30\% of the testdata, 1n,k1001 \leq n, k \leq 100.
For 80%80\% of the testdata, 1n,k50001 \leq n, k \leq 5000.
For 100%100\% of the testdata, 1n,k1051 \le n, k \le 10^5.

Translated by ChatGPT 5