Problem:
Score : 1800 points

Problem Statement

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

For each i (0 \leq i \leq 2N-1), N^2 \leq i^2+P_i^2 \leq (2N)^2 holds.

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

Constraints

1 \leq N \leq 250

2 \leq M \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

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

Sample Input 1

2 998244353

Sample Output 1

4

Four permutations satisfy the condition:

(2,3,0,1)

(2,3,1,0)

(3,2,0,1)

(3,2,1,0)

Sample Input 2

10 998244353

Sample Output 2

53999264

Sample Input 3

200 998244353

Sample Output 3

112633322

Solution in C# (Mono 4.6.2.0) (judge verdict: Time Limit Exceeded)

using System;
using System.Collections.Generic;

namespace Atcoder_program_test_Csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            //標準入力
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int M = int.Parse(str[1]);

            //変数宣言・初期化
            int i;//i
            int output_count = 0;//出力するためのカウント用変数
            int count;//
            int judgment = 1;//条件に当てはまるかの判定用変数

            //処理
            for (i = 0; i <= 2 * N - 1; i++)//大ループ iを変動させる。
            {
                for (count = 1; count != i;)//小ループ (2N-1)Pi の計算
                {
                    judgment =judgment * (2 * N - count);
                }
                if (N * N <= judgment)//N ^ 2 <= i ^ 2 + ((2N - 1)Pi) ^ 2の判定 
                {
                    if (judgment <= (2 * N) * (2 * N))//i ^ 2 + ((2N - 1)Pi) ^ 2 <= (2N) ^ 2の判定
                    {
                        output_count = output_count + 1;
                    }
                }
            }

            //出力
            Console.Write(output_count % M);
            Console.ReadKey();
        }
    }
}