const val MOD: Long = (1e9+7).toLong()

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{it.toInt()}

    var min = Int.MAX_VALUE
    for (i in -100..100) {
        val x = a.map{Math.pow((it-i).toDouble(), 2.0)}.sum().toInt()
        min = Math.min(min, x)
    }
    println(min)
}
