let n = stdin.ReadLine() |> int

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

let ans =
  [-100 .. 100]
  |> List.map (fun i -> a |> Array.sumBy (fun x -> (x - i) * (x - i)))
  |> List.min

ans |> stdout.WriteLine