object Main {
  def main(args: Array[String]): Unit = {
    val in = io.Source.fromInputStream(System.in).getLines()
    val N = in.next().toInt
    val A = in.next().split(' ') map (_.toInt)
    System.out.println(solve(N, A))
  }

  def solve(N: Int, A: Array[Int]): Int = {
    ((-100 to 100) map { i =>
      (A.indices map { j =>
        val d = i - A(j)
        d * d
      }).sum
    }).min
  }
}