Combinatoral Geometry with Distances The following problem is from Stars of Mathematics Senior P4
Let $S$ be a finite set of points in the plane,situated in general position (any three points in $S$ are not collinear), and let $$D(S,r)=\{\{x,y\}:x,y\in S,\text{dist}(x,y)=r\},$$where $r$ is a positive real number, and $\text{dist}(x,y)$ is the distance between points $x$ and $y$. 
Prove that $$\sum_{r>0}|D(S,r)|^2\le\frac{3|S|^2(|S|-1)}{4}.$$
Now we already know that $\sum_{r>0} |D(S,r)| = \frac{|S|(|S|-1)}{2}$.
Also, it is not difficult to prove that there are at least $\lceil \frac{n-1}{3} \rceil$ distances in this configuration.
Let there be $d_i$ distances from $P_i$, i.e. there are $d_i$ distances in $P_iP_j$, for $1 \le j \not= i \le n$.
Count the multiplicities of each distance by $f(i,j)$ where $1 \le j \le d_i$.
Note that $\sum_{j=1}^{d_i} f(i,j) = n-1$.
Now let us count the $(P_i, P_j,P_k)$ so that $P_iP_j=P_iP_k$. There are at most $2 \cdot \binom{n}{2}$ pairs since for two points, there are at most two points equidistant from both of them. Note that no $3$ points are collinear.
Also, the number of such pairs can be written as $$\sum_{i=1}^n \sum_{j=1}^{d_i} \binom{f(i,j)}{2}$$ 
Now Jensen's Inequality and Cauchy-Schwarz gives $$2 \cdot \binom{n}{2} \ge \sum_{i=1}^n \sum_{j=1}^{d_i} \binom{f(i,j)}{2} \ge \sum_{i=1}^n d_i \cdot \frac{1}{2} \cdot \frac{n-1}{d_i} \cdot (\frac{n-1}{d_i}-1) \ge n \cdot d \cdot \frac{n-1}{d} \cdot (\frac{n-1}{d}-1)=\binom{n}{2} \cdot (\frac{n-1}{d}-1)$$ so $3d \ge n-1$, where $d$ is the maximum of all $d_i$s. This gives the result.
Now the R.H.S looks (approximately) $$\frac{(\sum_{r>0} |D(S,r)|)^2}{\lceil \frac{|S|-1}{3} \rceil} \sim \frac{3}{4} |S|^3 $$ but I have no idea how to continue since Cauchy-Schwarz is guaranteed to give a lower bound.
 A: Here is the official solution:
Given a point $x$ in $S$ and a real number $r$,let $S(x,r)=\{y:y\in S,\text{dist}(x,y)=r\}$,and notice that the $S(x,r),r\ge 0$,partition $S$.
The number of non-degenerate isosceles triangles with vertices in $S$ and apex at $x$ is $\sum_{r>0}\binom{|S(x,r)|}{2}$,so the total number of non-degenerate isosceles triangles with vertices in $S$ is $N=\sum_{x\in S}\sum_{r>0}\binom{|S(x,r)|}{2}$,equilateral triangles with vertices in $S$ being counted three times each.Now,
\begin{align*}
N & =\sum_{x\in S}\sum_{r>0}\binom{|S(x,r)|}{2}=\sum_{r>0}\sum_{x\in S}\binom{|S(x,r)|}{2} \\
     &     \ge \sum_{r>0}|S|\binom{\frac{1}{|S|}\sum_{x\in S}|S(x,r)|}{2}=\sum_{r>0}|S|\binom{\frac{2|D(S,r)|}{|S|}}{2} \\
     & =\frac{2}{|S|}\sum_{r>0}|D(S,r)|^2-\sum_{r>0}|D(S,r)|=\frac{2}{|S|}\sum_{r>0}|D(S,r)|^2-\binom{|S|}{2},
\end{align*}
by Jensen's inequality applied to the convex function $t\to \binom{t}{2}=\frac{t(t-1)}{2},t\in\mathbb{R}$.
On the other hand,given two distinct points $x$ and $y$ in $S$,there are at most two non-degenerate isosceles triangles with vertices in $S$,base $xy$,and apex at a third point $S- \{x,y\}:$ the apex must lie on the perpendicular bisector of segment $xy$,and since no three points in $S$ are collinear,there are at most two such.Hence $N\le 2\binom{|S|}{2}$.
Combining the lower and the upper bounds for $N$ and rearranging terms yields the required inequality.
