fun main(args: Array<String>) {
    readLine()
    val x = readLine()!!.split(" ").map{ it.toInt() }
    val min = x.min()!!
    val max = x.max()!!
    var res: Int? = null
    for (i in min..max) {
        var tmp = 0;
        x.forEach { tmp += Math.pow((it-i).toDouble(), 2.0).toInt() }
        res = if (res == null) tmp else Math.min(res, tmp)
    }
    println(res)
}