import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine()
  val a = StdIn.readLine().split(" ").map(_.toInt)
  val r = a.sorted.sliding(2).foldLeft(0)((acc, ai) => acc + ai(1) - ai(0))
  println(r)

}
