In section 2.2 of this paper, Gelman and Park present the following identity for the gradient of the least squares line through a set of 2D points:
...we recall a simple algebraic identity that expresses the least-squares regression of $y$ on $x$ as a weighted average of all pairwise comparisons:
$$\begin{align} \hat\beta^{ls}&=\frac{\sum_i(y_i-\bar y)(x_i-\bar x)}{\sum_i(x_i-\bar x)^2}\\\\ &=\frac{\sum_{i,\,j}(y_i-y_j)(x_i-x_j)}{\sum_{i,\,j}(x_i-x_j)^2}\\\\ &=\frac{\sum_{i,\,j}\frac{y_i-y_j}{x_i-x_j}(x_i-x_j)^2}{\sum_{i,\,j}(x_i-x_j)^2}\end{align}$$
In the first line, which is a basic least squares result, the series are iterating over all the points. In the second and third lines the series are iterating over all pairs of points.
It feels like I might be missing something obvious, but how do we go from the first line to the second?