5. A drawer contains red and blue socks, with a total number not exceeding 2016. If two socks are randomly drawn, the probability that they are the same color is $\frac{1}{2}$. Then the maximum number of red socks in the drawer is _. $\qquad$
5.990.

Let \( x \) and \( y \) be the number of red and blue socks in the drawer, respectively. Then
\[
\frac{x y}{\binom{x+y}{2}} = \frac{1}{2} \Rightarrow (x-y)^2 = x + y.
\]

Thus, the total number of socks is a perfect square.
Let \( n = x - y \), i.e., \( n^2 = x + y \). Therefore, \( x = \frac{n^2 + n}{2} \).
Since \( x + y \leq 2016 \), it follows that \( n \leq 44 \) and \( x \leq 990 \).
Hence, the maximum number of red socks in the drawer is 990.