fun main(s: Array<String>) {
  readLine()!!
  val t = readLine()!!.split(' ').map { it.toInt() }
  val q = (1.0 * t.sum() / t.size).toInt()
  println((q-1..q+1).map { cost(t, it) }.min())
}

fun cost(nums: List<Int>, pt: Int) = nums.sumBy { (it - pt) * (it - pt) }