#P3913. 车的攻击

车的攻击

Description

On an N×NN \times N chessboard, there are KK rooks. The ii-th rook is located at row RiR_i and column CiC_i. Find the number of cells attacked by at least one rook.

A rook can attack all cells in the same row or the same column.

Input Format

The first line contains 2 integers N,KN, K.

The next KK lines each contain 2 integers Ri,CiR_i, C_i.

Output Format

Output one integer, the number of cells that are attacked.

3 2
1 2
2 2
7

Hint

• For 30% of the testdata, 1N103;1K1031 \le N \le 10^3; 1 \le K \le 10^3.

• For 60% of the testdata, 1N106;1K1061 \le N \le 10^6; 1 \le K \le 10^6.

• For 100% of the testdata, $1 \le N \le 10^9; 1 \le K \le 10^6; 1 \le R_i, C_i \le N$.

Translated by ChatGPT 5