object Main extends App {
  import scala.io.StdIn.readInt
  import scala.io.StdIn.readLine
  import scala.math.floor
    var n = readInt
    var num = readLine.split(" ").map(_.toInt).toIndexedSeq
  
  	def heiho(arr:IndexedSeq[Int]):Int = {
    return floor((arr.sum.toDouble / arr.length.toDouble) + 0.5).toInt
    }
  
    def nolmsum(x:Int,arr:IndexedSeq[Int]):Int = {
  	return arr.map(a =>(a - x) * (a - x)).sum
  }
    println(nolmsum(heiho(num),num).toString);
}