Given a point x in S and a real number r, let S(x,r)={y:y∈S,dist(x,y)=r}, and notice that the S(x,r), r≥0, partition S.
The number of non-degenerate isosceles triangles with vertices in S and apex at x
is ∑r>0(∣S(x,r)∣)2, so the total number of non-degenerate isosceles triangles with vertices
in S is N=∑x∈S∑r>0(2∣S(x,r)∣), equilateral triangles with vertices in S being counted three times each. Now,
N=x∈S∑r>0∑(2∣S(x,r)∣)=r>0∑x∈S∑(2∣S(x,r)∣)≥r>0∑∣S∣(2∣S∣1∑x∈S∣S(x,r)∣)=r>0∑∣S∣(2∣S∣2∣D(S,r)∣)=∣S∣2r>0∑∣D(S,r)∣2−r>0∑∣D(S,r)∣=∣S∣2r>0∑∣D(S,r)∣2−(2∣S∣),