#abc377f. F - Avoid Queen Attack

F - Avoid Queen Attack

Score : 550550 points

问题陈述

有一个由 N2N^2 个方格组成的网格,包含 NN 行和 NN 列。用 (i,j)(i,j) 表示从顶部数第 ii 行(1iN1\leq i\leq N)和从左边数第 jj 列(1jN1\leq j\leq N)的方格。

每个方格要么为空,要么上面放置了一个棋子。网格上放置了 MM 个棋子,第 kk 个(1kM1\leq k\leq M)棋子放置在方格 (ak,bk)(a_k,b_k) 上。

你想要在一个空方格上放置你的棋子,使得它不能被任何现有的棋子捕获

放置在方格 (i,j)(i,j) 上的棋子可以捕获满足以下任一条件的棋子:

  • 放置在第 ii
  • 放置在第 jj
  • 放置在任何满足 i+j=a+bi+j=a+b 的方格 (a,b) (1aN,1bN)(a,b)\ (1\leq a\leq N,1\leq b\leq N)
  • 放置在任何满足 ij=abi-j=a-b 的方格 (a,b) (1aN,1bN)(a,b)\ (1\leq a\leq N,1\leq b\leq N)

例如,放置在方格 (4,4)(4,4) 上的棋子可以捕获下图中蓝色显示的方格上的棋子:

你可以在多少个方格上放置你的棋子?

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There is a grid of N2N^2 squares with NN rows and NN columns. Let (i,j)(i,j) denote the square at the ii-th row from the top (1iN)(1\leq i\leq N) and jj-th column from the left (1jN)(1\leq j\leq N).

Each square is either empty or has a piece placed on it. There are MM pieces placed on the grid, and the kk-th (1kM)(1\leq k\leq M) piece is placed on square (ak,bk)(a_k,b_k).

You want to place your piece on an empty square in such a way that it cannot be captured by any of the existing pieces.

A piece placed on square (i,j)(i,j) can capture pieces that satisfy any of the following conditions:

  • Placed in row ii
  • Placed in column jj
  • Placed on any square (a,b) (1aN,1bN)(a,b)\ (1\leq a\leq N,1\leq b\leq N) where i+j=a+bi+j=a+b
  • Placed on any square (a,b) (1aN,1bN)(a,b)\ (1\leq a\leq N,1\leq b\leq N) where ij=abi-j=a-b

For example, a piece placed on square (4,4)(4,4) can capture pieces placed on the squares shown in blue in the following figure:

How many squares can you place your piece on?

Constraints

  • 1N1091\leq N\leq10^9
  • 1M1031\leq M\leq10^3
  • 1akN,1bkN (1kM)1\leq a_k\leq N,1\leq b_k\leq N\ (1\leq k\leq M)
  • (ak,bk)(al,bl) (1k<lM)(a_k,b_k)\neq(a_l,b_l)\ (1\leq k\lt l\leq M)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM

a1a_1 b1b_1

a2a_2 b2b_2

\vdots

aMa_M bMb_M

Output

Print the number of empty squares where you can place your piece without it being captured by any existing pieces.

Sample Input 1

8 6
1 4
2 1
3 8
4 5
5 2
8 3

Sample Output 1

2

The existing pieces can capture pieces placed on the squares shown in blue in the following figure:

Therefore, you can place your piece on only two squares: squares (6,6)(6,6) and (7,7)(7,7).

Sample Input 2

1000000000 1
1 1

Sample Output 2

999999997000000002

Out of 101810^{18} squares, the squares that cannot be used are: squares in row 11, squares in column 11, and squares (1,1)(1,1), (2,2)(2,2), \ldots, (109,109)(10^9,10^9), totaling 3×10923\times10^9-2 squares.

Note that the answer may be 2322^{32} or greater.

Sample Input 3

20 10
1 4
7 11
7 15
8 10
11 6
12 5
13 1
15 2
20 10
20 15

Sample Output 3

77