  Let $S$ be a set of $n$ points in Euclidean $3$-space. Assign to each $x\in
S$ a distance $r(x)>0$, and let $e_r(x,S)$ denote the number of points in $S$
at distance $r(x)$ from $x$. Avis, Erd\H{o}s and Pach (1988) introduced the
extremal quantity $f_3(n)=\max\sum_{x\in S}e_r(x,S)$, where the maximum is
taken over all $n$-point subsets $S$ of 3-space and all assignments $r\colon
S\to(0,\infty)$ of distances. We show that if the pair $(S,r)$ maximises
$f_3(n)$ and $n$ is sufficiently large, then, except for at most $2$ points,
$S$ is contained in a circle $\mathcal{C}$ and the axis of symmetry
$\mathcal{L}$ of $\mathcal{C}$, and $r(x)$ equals the distance from $x$ to $C$
for each $x\in S\cap\mathcal{L}$. This, together with a new construction,
implies that $f_3(n)=n^2/4 + 5n/2 + O(1)$.
