let n = stdin.ReadLine() |> int

let a =
  stdin.ReadLine().Split(' ') |> Array.map int

let ans =
  let extremumCadidate =
    a
    |> Array.sum
    |> (fun sum -> (float sum) / (float n))
    |> floor
    |> int

  [extremumCadidate; extremumCadidate + 1]
  |> List.map (
    fun cad ->
      a
      |> Array.sumBy (fun x -> (x - cad) * (x - cad)))
  |> List.min

ans |> stdout.WriteLine