compute all pairs of distances