let n = stdin.ReadLine() |> int

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

let ans =
  let cost x =
    a |> Array.sumBy (fun y -> (y - x) * (y - x))

  [-100 .. 100]
  |> List.minBy cost
  |> cost

ans |> stdout.WriteLine