#P1448. [NOI1998] 围巾裁剪

[NOI1998] 围巾裁剪

Description

A tailor has a very precious silk scarf. Unfortunately, some parts of the scarf have been eaten by moths. The tailor certainly does not want to throw it away, so he plans to cut the scarf into two small scarves for his two daughters. Naturally, the larger the sum of the areas of the two small scarves, the better.

The scarf is an equilateral triangle, and each of its three sides is evenly divided into NN segments, that is, the equilateral triangle is evenly divided into N2N^2 cells, each of which is an equilateral triangle of area 11.

As shown in the figure for N=5N=5, the shaded cells represent the parts eaten by moths.
From top to bottom, the scarf is divided into NN rows:

  • The first row has 11 cell.
  • The second row has 33 cells, among which 22 are of the shape Δ\Delta and 11 is of the shape \nabla (we consider these two triangles to be the same shape).
  • The third row has 55 cells, among which 33 are of the shape Δ\Delta and 22 are of the shape \nabla, and so on.

We use coordinates (X,Y)(X, Y) to locate each cell. The cell in the first row has coordinates (1,1)(1, 1); for the second row, from left to right, the three cells have coordinates (2,1)(2, 1), (2,2)(2, 2), (2,3)(2, 3); and so on.

The cutting conditions for the scarf are as follows:

  1. The two small scarves must be exactly the same shape as the original large scarf, i.e., equilateral triangles.
  2. There must be no moth-eaten parts within either small scarf.
  3. Cutting must follow the cell boundaries.
  4. The total area of the two small scarves must be maximized.

In the figure, the optimal cutting method has been drawn with bold lines, and the sum of areas is 4+9=134+9=13.
Now you need to write a program to help the tailor solve this problem.

Input Format

  • The first line contains an integer NN (1N1001 \leq N \leq 100), indicating that the scarf is divided into N2N^2 cells in total.
  • The second line contains an integer MM (1MN221 \leq M \leq N^2 - 2), indicating that MM cells of the scarf have been eaten by moths.
  • The next MM lines each contain two positive integers XX and YY, which are the coordinates of the MM moth-eaten cells.

Adjacent items on the same line in the input file are separated by one or more spaces.

Output Format

Output a single integer, the maximum total area of the two small scarves you can cut out.

5
5
3 2
4 1
4 4
5 4
5 2
13

Hint

  • Sample explanation: As shown in the figure in the Description, the maximum total area of the two small scarves is 4+9=134+9=13.
  • Constraints:
    • For 50%50\% of the testdata, 1N501 \leq N \leq 50.
    • For 100%100\% of the testdata, 1N1001 \leq N \leq 100, 0MN220 \leq M \leq N^2 - 2, 1XN1 \leq X \leq N, 1Y2×N11 \leq Y \leq 2 \times N - 1.

The testdata are in Windows (CRLF) format.

Translated by ChatGPT 5