object Main extends App {
  import scala.io.StdIn._

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

  println(
    (-100 to 100).map(y ⇒ a.map(x ⇒ (x - y) * (x - y)).sum).min
  )
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}
