
object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt
    val A = Array.fill(N)(0)
    for (i <- 0 until N) A(i) = sc.nextInt
    val mu = A.sum / N
    val min1 = A.map(x => (x - mu)*(x-mu)).sum
    val min2 = A.map(x => (x - mu-1)*(x-mu-1)).sum
    val min = if (min1 > min2) min2 else min1
    println(min)
  }
}