object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a = List.fill(n)(sc.nextInt())
  val ans = (-100 to 100).map{ x =>
    a.map{i =>
      val d = (i - x).abs
      d * d
    }.sum
  }.min
  println(ans)
}
