let cost_to_n list n =
  List.fold_left (fun x y -> x + y) 0 (List.map (fun x -> (n-x)*(n-x)) list)

let solve list =
  let rec aux list min_cost cto cfrom cnow =
    if cnow = cto then min_cost else
      let cur_cost = cost_to_n list cnow in
      aux list (min min_cost cur_cost) cto cfrom (cnow+1)
  in
  aux list 99999999
      (List.fold_left (fun x y -> max x y) 0 list)
      (List.fold_left (fun x y -> min x y) 99999999 list)
      (List.fold_left (fun x y -> min x y) 9999999 list)
    

let read_list_of_int () =
  let rec read_list_of_int_inner lst =
    try let ans = (Scanf.scanf "%d " (fun x->x)) in
        read_list_of_int_inner (ans::lst)
    with End_of_file ->
      List.rev lst
  in
  read_list_of_int_inner []

let () =
  let _ = read_int() in
  let list = read_list_of_int () in
  let ans = solve list in
  Printf.printf "%d\n" ans
;;