atcoder#AGC036F. [AGC036F] Square Constraints

[AGC036F] Square Constraints

Score : 18001800 points

Problem Statement

Given is an integer NN. How many permutations (P0,P1,,P2N1)(P_0,P_1,\cdots,P_{2N-1}) of (0,1,,2N1)(0,1,\cdots,2N-1) satisfy the following condition?

  • For each ii (0i2N1)(0 \leq i \leq 2N-1), N2i2+Pi2(2N)2N^2 \leq i^2+P_i^2 \leq (2N)^2 holds.

Since the number can be enormous, compute it modulo MM.

Constraints

  • 1N2501 \leq N \leq 250
  • 2M1092 \leq M \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

Output

Print the number of permutations that satisfy the condition, modulo MM.

2 998244353
4

Four permutations satisfy the condition:

  • (2,3,0,1)(2,3,0,1)
  • (2,3,1,0)(2,3,1,0)
  • (3,2,0,1)(3,2,0,1)
  • (3,2,1,0)(3,2,1,0)
10 998244353
53999264
200 998244353
112633322