  // C - いっしょ / Be Together https://atcoder.jp/contests/abc043/tasks/arc059_a

  import io.Source

  object Main extends App {
    val xs = Source.stdin.getLines()
    val n = xs.next().toInt
    val ns = xs.next().split(' ').map(_.toInt)

    println(solve(ns))

    def solve(ns: Seq[Int]): String = {
      // 総当り
      var ans = Int.MaxValue
      (-100 to 100).foreach { n =>
        val a = cost(n, ns)
        ans = Math.min(a, ans)
      }
      ans.toString
    }

    def cost(n: Int, ns: Seq[Int]): Int = {
      ns.map(m => Math.pow(m - n, 2).toInt).sum
    }
  }
