import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val as = new Array[Int](n)
    for (i <- 0 until n) {
      as(i) = sc.nextInt()
    }

    val sum = as.sum
    val average = math.round(sum.toDouble / as.length.toDouble)

    var ans = 0L
    for (i <- as.indices) {
      ans += math.pow(as(i) - average, 2).toLong
    }

    println(ans)
  }
}