fun main(argv: Array<String>) {
    val line = readLine()
    val splited = readLine()!!.split(' ')
    val intArr = splited.map { Integer.parseInt(it) }

    val average = Math.round(intArr.average()).toInt()
    var cost = 0

    for (number in intArr) {
        cost += Math.pow((number - average).toDouble() ,2.0).toInt()
    }
    print(cost)
}