Simplifying $\sum(Y_i-\bar{Y})^2$ My textbook tells me that for a random sample $Y_1, Y_2, \dots, Y_n$ where $E(Y_i)=\mu, V(Y_i)=\sigma^2$:
$\displaystyle\sum_{i=1}^n (Y_i-\bar{Y})^2 = \sum_{i=1}^nY_i^2-\frac{1}{n}(\sum_{i=1}^n Y_i)^2 = \sum_{i=1}^n Y_i^2-n\bar{Y}^2$
I'm sorry if this is a horrifically dumb question, but I don't understand how these are equivalent. When I do the math on the first summation on the lefthand side (aka foil it out), I have a $-2Y_i\bar{Y}$ term that isn't represented in the middle equation.
Again, my apologies if this is not the correct place for a silly algebra question such as this. I will delete if necessary.

\begin{eqnarray}
\sum_{i=1}^n (Y_i-\bar{Y})^2 &=& \sum_{i=1}^n (Y_{i}^{2}-2Y_{i}\bar{Y}+\bar{Y}^{2}) \\
                             &=& \sum_{i=1}^n Y_{i}^{2}-  2 \bar{Y} \sum_{i=1}^n Y_{i}-n \bar{Y}^{2} \\
                             &=& \sum_{i=1}^n Y_{i}^{2} - 2n\bar{Y}^{2}+n\bar{Y}^{2} \\
                             &=& \sum_{i=1}^n Y_{i}^{2} - n\bar{Y}^{2}
\end{eqnarray}
