The sum of squared distances under a diameter constraint, in arbitrary dimension