Let $n$ be an integer. I'm interested in upper bounding the number of integer solutions of \begin{equation*} x_1^2+x_2^2+\ldots+x_p^2=y_1^2+y_2^2+\ldots+y_p^2, \end{equation*} where for all $i\in\{1,2,\ldots,p\}$ $x_i$ and $y_i$ are integers obeying
\begin{equation*} 0\le x_i\le n-1\\ 0\le y_j\le n-1 \end{equation*}
Alternatively stated I'm interested in upper bounding the sum \begin{equation*} \sum_{x_1,x_2,\ldots,x_p=0}^{n-1}\sum_{y_1,y_2,\ldots,y_p=0}^{n-1}\delta\Big(x_1^2+x_2^2+\ldots+x_p^2-\big(y_1^2+y_2^2+\ldots+y_p^2\big)\Big) \end{equation*} where $\delta(t)$ is the Kronecker delta function with has value $1$ at $t=0$ and zero everywhere else.
FYI, the reason I'm interested in this is because I would like to bound the following quantity. Let $\mathbf{z}\in\mathbb{C}^n$ with entries $z_1,z_2,\ldots,z_n$. I would like to bound the following quantity
\begin{equation*} f(\mathbf{z})=\sum_{x_1,x_2,\ldots,x_p=0}^{n-1}\sum_{y_1,y_2,\ldots,y_p=0}^{n-1}\big(\prod_{i=1}^p z_{x_i}\big)\big(\prod_{j=1}^p\bar{z}_{y_j}\big)\delta\Big(x_1^2+x_2^2+\ldots+x_p^2-\big(y_1^2+y_2^2+\ldots+y_p^2\big)\Big) \end{equation*} where $\bar{z}$ denotes the conjugate of $z$. I was thinking of using the bound \begin{align*} |f(\mathbf{z})|\le\|\mathbf{z}\|_{\ell_\infty}^{2p}\Big(\sum_{x_1,x_2,\ldots,x_p=0}^{n-1}\sum_{y_1,y_2,\ldots,y_p=0}^{n-1}\delta\Big(x_1^2+x_2^2+\ldots+x_p^2-\big(y_1^2+y_2^2+\ldots+y_p^2\big)\Big)\Big) \end{align*} If anybody has any ideas on bounding $|f(\mathbf{z})|$ in terms of $\|\mathbf{z}\|_{\ell_2}^{2p}$ that would be perfect. Here $\|\mathbf{z}\|_{\ell_\infty}$ and $\|\mathbf{z}\|_{\ell_2}$ denotes the maximum absolute value of the entries of $\mathbf{z}$ and the Euclidean norm of $\mathbf{z}$ respectively.