object Main extends App{
    val n = scala.io.StdIn.readInt
    val x = scala.io.StdIn.readLine.split(" ").map(_.toInt).sorted
    val output = (x.head to x.last).map(e => (for(count <- x) yield (e-count)*(e-count)).sum).min
    println(output)
}
