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

        val min = x.min()!!
        val max = x.max()!!

        var total = 0
        for (i in min..max) {
            var tmp = 0
            x.forEach {
                tmp += (it - i) * (it - i)
            }
            if (i == min) {
                total = tmp
            }

            if (total > tmp) {
                total = tmp
            }
        }
        println(total)
    }
