import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val as = List.fill(n)(sc.nextInt)

  val sum = as.sum
  val mean =
    if (sum < 0) (sum * 10 / n - 5) / 10
    else (sum * 10 / n + 5) / 10

  def d(n: Int): Int = n * n

  val ans = as.fold(0) { (acc, next) => acc + d(next - mean) }

  println(ans)
}
