What is the $(\sum_{i} X_i)^2$ equal to? We have an indicator Random Variable $X_i$, that takes either the value 0 or the value 1. I read that the square of its sum is:
$$\left(\sum_{i} X_i\right)^2 = \sum_{i} X_i^2 + \sum_{i,j: i \neq j} X_iX_j$$
Why is this true and how many terms are in the second summation ($\sum_{i,j: i \neq j} X_iX_j$), if there are n terms in general?
 A: This is just using the distributive property to multiply out $$ (X_1+X_2+\ldots+X_n)(X_1+X_2+\ldots +X_n).$$ There is a direct term $X_i^2$ for every $i$ and then there are cross terms. For instance, we have $X_1 X_2$ from the $X_1$ in the left factor, multiplied by the $X_2$ in the right factor, and then an $X_2X_1$ from the $X_2$ in the left factor multiplied by the $X_1$ in the right. So there is a cross term $X_iX_j$ for every pair $(i,j)$ with $1\le i\le n$ and $1\le j \le n$ and $i\ne j.$ 
How many terms there are are just how many such pairs. This is the number of ways of choosing $2$ different numbers from $\{1,\ldots, n\},$ where the ordering matters. This should be familiar if you've seen any combinatorics. There are $n$ choices for the first number and $n-1$ choices for the second number. So the total is $n(n-1).$ 
Notice that these terms come in pairs: you get both a $X_1X_2$ term and a $X_2 X_1$ term, which are the same thing. So you will often also see the crossterms written $$ 2\sum_{i<j} X_i X_j,$$ in which case there are $\frac{n(n-1)}{2}$ terms in the sum (we've just collected pairs of equal terms together, thus the factor of $2$ out front).
