average distance script