let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ ->
    Scanf.scanf "%d " @@ fun a -> a in
  let cost x =
    Array.fold_left ( + ) 0 @@
    Array.map (fun y -> (x - y) * (x - y)) as_ in
  Printf.printf "%d\n" @@ cost @@ upper_bound (-100) 100 @@ fun i ->
    cost i - cost (i - 1) <= 0
