5. A bag contains $n$ red balls and 5 white balls. It costs 1 yuan to draw once, and each time two balls are drawn from the bag at once. If the two balls are of different colors, it is considered a win, and the prize is 2 yuan. Then when $n=$ $\qquad$, the expected value is maximized.
Let the probability of winning once be $p_{n}$. Then
$$
p_{n}=\frac{\mathrm{C}_{n}^{1} \mathrm{C}_{5}^{1}}{\mathrm{C}_{n+5}^{2}}=\frac{10 n}{(n+5)(n+4)} \text {. }
$$

By the problem, if you win, you earn 1 yuan; if you don't win, you lose 1 yuan. Therefore, the mathematical expectation is
$$
E=p_{n}-\left(1-p_{n}\right)=2 p_{n}-1 .
$$

This problem is converted to finding $n$ that maximizes $p_{n}$.
$$
\begin{array}{l}
\text { Let } f(x)=\frac{10 x}{(x+5)(x+4)}=\frac{10}{x+\frac{20}{x}+9}, \\
g(x)=x+\frac{20}{x} .
\end{array}
$$

It is easy to see that $g(x)$ is monotonically decreasing in the interval $(0, \sqrt{20})$ and monotonically increasing in the interval $(\sqrt{20},+\infty)$.
Since $n \in \mathbf{Z}_{+}, g(4)=g(5)=9$, hence $g(n)_{\min }=9$.
At this point, $p_{n}$ reaches its maximum value.
Therefore, when $n=4$ or 5, the mathematical expectation reaches its maximum value.