fun main(args: Array<String>) {
  val sq = {x:Int -> x*x}
  val N = readLine()!!.toInt()
  val A = readLine()!!.split(" ").map(String::toInt)
  val avr = A.average()
  val avrI = avr.toInt() + if(avr-avr.toInt() < 0.5)0 else 1
  print(A.map{sq(it-avrI)}.sum())
}