object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val length = sc.nextInt()
    val input: Array[Int] = Array.fill(length)(sc.nextInt())

    val min = input.min
    val max = input.max
    val ans = min
      .to(max)
      .map { position =>
        input.map(_ - position).map(distance => distance * distance).sum
      }
      .min

    println(ans)
  }
}
