import scala.io.StdIn._

object Main extends App {

  val n = readInt()
  val a = readLine().split(" ").map(_.toInt)

  def solve() = {
    val ave = (a.sum.toDouble / a.length).ceil.toInt
    a.foldLeft(0) { (acc, num) =>
      acc + (num - ave) * (num - ave)
    }
  }
  println(solve())

}

