Skip to main content
1 of 8
Arnauld
  • 197.8k
  • 20
  • 179
  • 650

#JavaScript (ES6), 160 bytes

n=>(g=(o,v,p)=>[...Array(N=2*n),p+N-1,p+1,p+n].reduce((s,x,i)=>v>>(x=i<N?i:x%N)&1?s:s+g((i>=N)/p?[...o,p<x?p*n*n+x:x*n*n+p]:o,v|1<<x,x),g[o.sort()]^(g[o]=1)))``

Try it online!

Arnauld
  • 197.8k
  • 20
  • 179
  • 650