import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val N = scn.nextInt()

    var list = arrayListOf<Int>()

    for(i in 1 .. N){
        list.add(scn.nextInt())
    }
    list.sort()

    var min = Integer.MAX_VALUE
    for(i in list.first() .. list.last()){
        var sum = 0
        for(j in list){
            sum += (j-i)*(j-i)
        }

        if(sum<=min) min=sum
    }

    println(min)
}