Average speed = (total distance traveled)/(total travel time)
= (total distance)/(time of 1st journey + time of 2nd journey + time of 3rd journey)
Let d = the distance between Town A and Town B
So, total distance traveled = 3d
Time = distance/speed
time of 1st journey = d/x
time of 2nd journey = d/y
time of 3rd journey = d/z
Total time = d/x + d/y + dz
To simplify, rewrite with common denominator: dyz/xyz + dxz/xyz + dxy/xyz
So, total time = (dyz + dxz + dxy)/xyz
Average speed = (total distance)/(total time)
= 3d/[(dyz + dxz + dxy)/xyz]
= (3dxyz)/(dyz + dxz + dxy)
Divide top and bottom by d to get: (3xyz)/(yz + xz + xy)