let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref max_int
let _ = for i = -100 to 100 do ans := min !ans @@ Array.fold_left (fun s a -> s + (a - i) * (a - i)) 0 a_s done; Printf.printf "%d\n" !ans