Finding closed form of $\sum\limits_{r=0}^n r^2 \binom nr p^{n-r}q^r$ where $p>0$ and $q=1-p$ Here is a question from Indian Statistical Institute (ISI) Entrance Exam CSA-2020, Question 11:
$\binom n0, \binom n1,..., \binom nn$ denote the binomial coefficients in the expansion
of $(1 + x)^n \ \text{where} \ 
 p > 0$ is a real number and $q = 1 − p$ then
$$ 
\sum\limits_{r=0}^n r^2 \binom nr p^{n-r}q^r 
$$
is equal to
$
(A)\ np^2q^2 \
(B)\ n^2p^2q^2 \
(C)\ npq + n^2p^2 \
(D)\ npq + n^2q^2
$

My Thoughts: (1)
If I put the formula for $\binom nr$ in the given sum. I am getting
$$ 
\sum\limits_{r=0}^n r^2 \frac{n!}{r!(n-r)!} p^{n-r}q^r 
$$
How do I proceed after this?

Edit:
Taking help from here and the comments below I wrote the following, although I am stuck in the last step, please help me out.
$$
(1+x)^n=\sum\limits_{r=0}^n \binom nr x^r
$$
Taking derivative on both sides we have:
$$
n(1+x)^{n-1}=\sum\limits_{r=1}^n r\binom nr x^{r-1}
$$
Multiplying both sides by $x$ we get:
$$
nx(1+x)^{n-1}=\sum\limits_{r=1}^n r \binom nr x^r
$$
Taking derivative another time:
$$
n(1+x)^{n-1}+nx(n-1)(1+x)^{n-2}=\sum\limits_{r=1}^n r^2 \binom nr x^{r-1}
$$
Multiplying both sides by $x$ we get:
$$
nx(1+x)^{n-1}+nx^2(n-1)(1+x)^{n-2}=\sum\limits_{r=1}^n r^2 \binom nr x^r
$$
Given that $p>0$ and $q=1-p$ . So let $x=\frac qp$ then we have:
$$
n\frac qp\left(1+\frac qp\right)^{n-1}+
n\left(\frac qp\right)^2(n-1)\left(1+\frac qp\right)^{n-2}
=
\sum\limits_{r=1}^n r^2 \binom nr \left(\frac qp \right)^r
$$
$$
\implies 
n\frac qp\left(\frac{p+q}{p}\right)^{n-1}+
n\left(\frac qp\right)^2(n-1)\left(\frac{p+q}{p}\right)^{n-2}
=
\sum\limits_{r=1}^n r^2 \binom nr \left(\frac qp \right)^r
$$
$$
\implies 
n\frac qp \left(\frac{1}{p}\right)^{n-1}+
n\left(\frac qp\right)^2(n-1)\left(\frac{1}{p}\right)^{n-2}
=
\sum\limits_{r=1}^n r^2 \binom nr \left(\frac qp \right)^r \ \ \ \ \ 
[\text{Since}\ p+q=1]
$$
$$
\implies 
n\frac{q}{p^n}+
n(n-1)\frac{q^2}{p^n}
=
\sum\limits_{r=1}^n r^2 \binom nr \left(\frac qp \right)^r
$$
$$
\implies 
nq+
n(n-1)q^2
=
p^n\sum\limits_{r=1}^n r^2 \binom nr \left(\frac qp \right)^r
$$
$$
\implies 
nq+
n(n-1)q^2
=
\sum\limits_{r=1}^n r^2 \binom nr p^{n-r}q^r
$$
$$
\implies 
n(q-q^2)+
n^2q^2
=
\sum\limits_{r=1}^n r^2 \binom nr p^{n-r}q^r
$$
$$
\implies 
n\{(1-p)-(1-p)^2\}+
n^2q^2
=
\sum\limits_{r=1}^n r^2 \binom nr p^{n-r}q^r
$$
$$
\implies 
n\{(1-p)-(1+p^2-2p)\}+
n^2q^2
=
\sum\limits_{r=1}^n r^2 \binom nr p^{n-r}q^r
$$
$$
\implies 
np(1-p)+
n^2q^2
=
\sum\limits_{r=1}^n r^2 \binom nr p^{n-r}q^r
$$
$$
\implies 
npq+
n^2q^2
=
\sum\limits_{r=1}^n r^2 \binom nr p^{n-r}q^r
$$
Hence option (D) is correct.

This question is almost similar to this question but is slightly different. So I have added this question.
 A: Hint 1: $$r\binom{n}{r}=n\binom{n-1}{r-1}$$
Hint 2: $$r\binom{n-1}{r-1}=(r-1+1)\binom{n-1}{r-1}=\text{??}$$
Also note that you can take some $p$s and $q$s out of the summation (since they're constants) to match the upper index of the binomial.
A: You probably know that the expected number of successes in $n$ independent trials with probability $p$ of success on each trial is $np,$ and that the variance of the number of successes is $npq=np(1-p).$
Now recall that the expected value of the square of a random variable is the variance plus the square of the expected value.
Therefore you get $npq + n^2p^2.$
A: Let $$f(q) = (p+q)^n = \sum_{r = 0}^{n} \binom{n}{r}p^{n-r}q^r$$
Then $$q \frac{df}{dq} = q\sum_{r = 0}^{n} r\binom{n}{r}p^{n-r}q^{r-1} = \sum_{r = 0}^{n} r\binom{n}{r}p^{n-r}q^{r}$$ What just happened, by applying $q\frac{d}{dq}$ to $f(q)$, is each power $r$ of $q$ has been brought down from the exponent to multiply the coefficient of $q^r$. By doing this twice, one gets $$q\frac{d}{dq}\left(q\frac{df}{dq}\right) = q\left(\frac{df}{dq}+q\frac{d^2 f}{dq^2}\right) = q\frac{df}{dq}+q^2\frac{d^{2} f}{dq^2} = \sum_{r = 0}^{n} r^2 \binom{n}{r}p^{n-r}q^r$$ Plug in the original definition for $f(q)$ into this equation and evaluate at $q = 1-p$, then in your multiple choices, plug in $q = 1-p$, and then compare.
