Suppose that $X\sim\operatorname{Binomial}\left(n,p\right)$ and $Y = n - X$. How do I find $\mathbb{E}\left[XY\right]$? Consider a sequence of $ n $ independent bernoulli trials with a success probability of $ p $.
Let $ X $ be the number of successes and $ Y $ the number of failures.
Find $ \mathbb{E}\left[XY\right] $.
So, I'm kinda stuck in this exercise. I tried to build a table of the joint distribution and then write down the expected value to find some pattern but it doesn't look very helpful. Any help here?
 A: HINT
Based on @SeanRoberson's comment, you can proceed as follows:
\begin{align*}
\mathbb{E}[XY] & = \mathbb{E}[X(n - X)]\\\\
& = \mathbb{E}[nX - X^{2}]\\\\
& = \mathbb{E}[nX] - \mathbb{E}[X^{2}]\\\\
& = n\mathbb{E}[X] - \mathbb{V}[X] - \mathbb{E}[X]^{2}
\end{align*}
Can you take it from here?
A: As stated in the comments, $X,Y$ are linearly related:
$$X + Y = n \implies Y = n-X \implies \mathbb{E}\left[XY\right]=\mathbb{E}\left[X\left(n-X\right)\right]=n\mathbb{E}\left[X\right]-\mathbb{E}\left[X^2\right]$$
Note that $X\sim \operatorname{Binomial}\left(n,p\right)$, therefore:
$$\mathbb{E}\left[X\right]=np,\;\;\operatorname{Var}\left[X\right]=\mathbb{E}\left[X^2\right]-\left(\mathbb{E}\left[X\right]\right)^2 = np\left(1-p\right) \implies np\left(1-p\right)=\mathbb{E}\left[X^2\right]-n^2p^2$$
Collecting like powers of $p$ we get:
$$\mathbb{E}\left[X^2\right] = \left(n^2-n\right)p^2+np \implies n\mathbb{E}\left[X\right]-\mathbb{E}\left[X^2\right]=n^2p-np-\left(n^2-n\right)p^2 =\left(n^2-n\right)\left(p-p^2\right)$$
