How many ways to write numbers as sums of squares? Task
Given two integers \$d\$ and \$n\$, find the number of ways to express \$n\$ as a sum of \$d\$ squares. That is, \$n = r_1^2 + r_2^2 + ... + r_d^2\$, such that \$r_m\$ is an integer for all integers \$1 ≤ m ≤ d\$. Note that swapping two different values (e.g. \$r_1\$ and \$r_2\$) is considered different from the original solution.
For instance, the number 45 can be written as a sum of 2 squares 8 different ways:
$$\begin{align}
&amp; 45 \\
&amp; = (-6)^2 + (-3)^2 \\
&amp; = (-6)^2 + 3^2 \\
&amp; = (-3)^2 + (-6)^2 \\
&amp; = (-3)^2 + 6^2 \\
&amp; = 3^2 + (-6)^2 \\
&amp; = 3^2 + 6^2 \\
&amp; = 6^2 + (-3)^2 \\
&amp; = 6^2 + 3^2
\end{align}$$
Rules

Built-in solutions are allowed but non-competing (ahem, Mathematica)
Standard loopholes are also forbidden.
The inputs may be reversed.

Example I/O
In:   d, n

In:   1, 0
Out:  1

In:   1, 2
Out:  0

In:   2, 2
Out:  4

In:   2, 45
Out:  8

In:   3, 17
Out:  48

In:   4, 1000
Out:  3744

In:   5, 404
Out:  71440

In:   11, 20
Out:  7217144

In:   22, 333
Out:  1357996551483704981475000

This is code-golf, so submissions using the fewest bytes win!
Python 3, 125 bytes



n,d=eval(input())
W=[1]+[0]*n
exec("W=[sum(-~(j&gt;0)*W[i-j*j]for j in range(int(i**.5)+1))for i in range(n+1)];"*d)
print(W[n])


Try it online!

Finishes the last testcase in 0.078 s. Naive complexity is O(d n 2).