#P15500. [ICPC 2025 APC] Squares on Grid Lines

[ICPC 2025 APC] Squares on Grid Lines

Description

You have a square of side length nn on a 2D plane, partitioned into a grid of 1×11 \times 1 square cells, totaling n2n^{2} cells.

Your task is to answer qq queries, numbered from 11 to qq, described below. In query ii, you are given a real number sis_{i}, and you must count the number of ways to place four points on the plane such that

  • each point lies on the boundary of a cell (not necessarily the same), and
  • the four points form the vertices of a square with area sis_{i}.

Here, the edges of the square formed by these points do not need to be parallel to the edges of the cells. If there are infinitely many valid placements, you must report that as your answer.

Two placements are considered different if there exists a point that appears in one placement but not in the other.

Input Format

The first line of input contains two integers nn and qq (1n20001 \leq n \leq 2000, 1q100 0001 \leq q \leq 100\ 000). The ii-th of the next qq lines contains a real number sis_{i} (0.01sin20.01 \leq s_{i} \leq n^{2}), given with exactly two digits after the decimal point.

Output Format

Output qq lines. The ii-th line should contain the number of valid placements for query ii. If infinitely many exist, output 1-1 instead.

3 4
6.90
0.26
2.65
1.00
2
4
10
-1
1 5
0.49
0.50
0.51
0.99
1.00
0
1
2
2
1

Hint

Explanation for the sample input/output #1

For queries 11 and 22, the valid placements are illustrated in Figure I.1. The top two placements correspond to query 11, and the bottom four correspond to query 22. In each placement, the shaded region represents a square formed by the points.

:::align{center}

Figure I.1: Illustrations of Sample Input #1. :::