let ($) f x = f x

type pos = {x:int; y:int}

exception No_more_candidate

let string_of_pos pos = Printf.sprintf "{x=%d, y=%d}" pos.x pos.y

let string_of_pos_array pos_array =
  String.concat ", "
    $ List.map (fun pos -> string_of_pos pos) (Array.to_list pos_array)

let load () =
  let n = int_of_string (read_line ()) in
  let positions = Array.make n {x = 0; y = 0} in
  for i = 0 to (n - 1) do
    let xy = String.split_on_char ' ' (read_line ()) in
    positions.(i) <- {
      x = (int_of_string $ List.nth xy 0);
      y = (int_of_string $ List.nth xy 1)
    };
  done;
  positions

let closest_dist positions =
  let len = Array.length positions in
  let closest_result = ref max_int in
  let closest_length = ref max_int in
  for i = 0 to (len - 1) do
    let pos = positions.(i) in
    try (
      for j = i + 1 to (len - 1) do
        let another_pos = positions.(j) in
        if another_pos.x - pos.x < !closest_length then (
          let result =
            (another_pos.x - pos.x) * (another_pos.x - pos.x) +
            (another_pos.y - pos.y) * (another_pos.y - pos.y) in
          if result < !closest_result then (
            closest_result := result;
            closest_length := int_of_float (sqrt $ float_of_int result)
          )
        )
        else
          raise No_more_candidate
      done
    ) with No_more_candidate -> ();
  done;
  !closest_result

let work_for_strip = Array.make 500000 {x=0; y=0}

let rec traverse positions =
  let len = Array.length positions in
  if len <= 1 then
    max_int
  else
    let mid = len / 2 in
    let mid_pos = positions.(mid) in
    let left_side = Array.sub positions 0 mid in
    let right_side = Array.sub positions (mid + 1) (len - (mid + 1)) in
    let dl = traverse left_side in
    let dr = traverse right_side in
    let d_both = min dl dr in
    let idx_of_strip = ref 0 in
    ignore (try (
      for i = 0 to (len - 1) do
        let pos = positions.(i) in
        if abs $ pos.x - mid_pos.x < d_both then (
          work_for_strip.(!idx_of_strip) <- pos;
          idx_of_strip := !idx_of_strip + 1;
        )
        else (
          if pos.x > mid_pos.x then
            raise No_more_candidate
        )
      done
    ) with No_more_candidate -> ());
    let d_strip = closest_dist $ Array.sub work_for_strip 0 (!idx_of_strip - 1) in
    min d_both d_strip

let () =
  let positions = load () in
  Array.sort (fun a b -> a.x - b.x) positions;
  print_int $ traverse positions;
  print_newline ()


