9. (14 points) Let there exist $n$ integers $a_{1}, a_{2}, \cdots, a_{n}$, such that $\prod_{i=1}^{n} a_{i}=n$, and $\sum_{i=1}^{n} a_{i}=0$. Find all possible values of the positive integer $n$.


9. First prove $4 \mid n$.
If $n$ is odd, then from $\prod_{i=1}^{n} a_{i}=n$, we know that $a_{1}, a_{2}, \cdots, a_{n}$ are all odd numbers.

Thus, $\sum_{i=1}^{n} a_{i}$ is the sum of an odd number of odd numbers, which cannot be 0, contradicting $\sum_{i=1}^{n} a_{i}=0$.
Therefore, $n$ is even.
From $\sum_{i=1}^{n} a_{i}=0$, we know that $a_{1}, a_{2}, \cdots, a_{n}$ contain an even number of odd numbers, and since $n$ is even, $a_{1}, a_{2}, \cdots, a_{n}$ contain an even number of even numbers. Also, it has been proven that $a_{1}, a_{2}, \cdots, a_{n}$ contain at least one even number, so $a_{1}, a_{2}, \cdots, a_{n}$ contain at least two even numbers. From $\prod_{i=1}^{n} a_{i}=n$, we know that $4 \mid n$.
On the other hand, when $n=8 k\left(k \in \mathbf{N}_{+}\right)$,
$$
\begin{array}{l}
n=8 k=2 \times 4 k \times 1^{2 k-2}(-1)^{6 k}, \\
2+4 k+(2 k-2)-6 k=0,
\end{array}
$$

it satisfies the conditions.
$$
\begin{array}{l}
\text { When } n=8 k+4\left(k \in \mathbf{N}_{+}\right) \text {, } \\
n=8 k+4=-2(4 k+2) \times 1^{2 k+1}(-1)^{6 k+1}, \\
-2+4 k+2+(2 k+1)-(6 k+1)=0,
\end{array}
$$

it satisfies the conditions.
In summary, $n=4 k\left(k \in \mathbf{N}_{+}\right)$.