modified average with sum of distance in query number 8