fun main(args: Array<String>) {
    readLine()!!
    val a = readLine()!!.split(" ").map(String::toInt)
    var minCost = Int.MAX_VALUE
    for (i in -100..100) {
        val cost = a.sumBy {
            val temp = it - i
            temp * temp
        }
        if (cost < minCost) {
            minCost = cost
        }
    }
    println(minCost)
}
