Assume the distance between Townsend and Smallville is X,
the time consumed from Townsend to Smallville is X/40,
and the time consumed from Smallville to Townsend is (X/40)*3/2,
so clearly the total time spent equals 2X/[X/40+(X/40)*3/2]=32.
Hope it explains clearly to you.