Scanf.scanf "%d" (fun n ->
    let d = Array.init n (fun _ -> Scanf.scanf " %d" (fun d -> d)) in
    Array.sort compare d;

    let calc l =
        let a = Array.of_list l in
        Array.sort compare a;

        let rec loop i acc = 
            if i = n + 1 then acc else
                loop (i + 1) (min acc (abs (a.(i) - a.(i - 1))))
        in
        loop 1 12
    in

    let rec loop i flag acc =
        if i = n then calc acc else
            loop (i + 1) (not flag) ((if flag then d.(i) else 24 - d.(i)) :: acc)
    in
    loop 0 true [ 0 ] |> Printf.printf "%d\n"
)