import scala.math.abs
 
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val as = Array.fill(n)(sc.nextInt())
  val t = math.round(as.sum.toDouble / as.length).toInt
  val ans = as.foldLeft(0)((x, y) => x + math.pow(y - t, 2).toInt)
  println(ans)
}