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++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
const int N=255;
int n,mo,i,j,k,l,lo[N*2],hi[N*2],f[2][N],nw,ans;
inline int F(int x){return x>0?x:0;}
int main(){
	scanf("%d%d",&n,&mo);
	for(i=0;i<n*2;++i)hi[i]=sqrt(n*n*4-i*i),lo[i]=i<n?sqrt(n*n-i*i-1):0;hi[0]=2*n-1;
	for(l=0;l<=n;++l){
		memset(f,0,sizeof f);nw=0;f[0][0]=1;
		for(i=j=0;i<n || j<n;){
			nw^=1;memset(f[nw],0,n+1<<2);
			if(i<n && (j==n || lo[n-1-i]<=hi[n*2-1-j])){
				for(k=0;k<=l && k<=i+1;++k)
					f[nw][k]=(1ll*f[!nw][k]*F(hi[n-1-i]+1-(i-k)-l-n)+(k?1ll*f[!nw][k-1]*F(lo[n-1-i]+1-(k-1)-j):0))%mo;
				++i;
			}else{
				for(k=0;k<=l && k<=i;++k)
					f[nw][k]=1ll*f[!nw][k]*F(hi[n*2-1-j]+1-k-j)%mo;
				++j;
			}
		}
		ans=(ans+(l&1?mo-f[nw][l]:f[nw][l]))%mo;
	}
	printf("%d\n",ans);
	return 0;
}