import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val n = in.readLine().toInt
    val as = in.readLine().split("\\s+").map(_.toInt)

    out.println(
      (as.min to as.max).foldLeft(Int.MaxValue) {
        case (min, t) =>
          Math.min(min, as.foldLeft(0) {
            case (sum, a) => sum + (a - t) * (a - t)
          })
      }
    )

    out.flush()
  }
}
