Scanf.scanf "%d %d" (fun n k ->
    let count = Array.make 40 0 in
    let a = Array.init n (fun i ->
        Scanf.scanf " %d" (fun a ->
            let rec loop j r =
                if r = 0 then a else (
                    count.(j) <- count.(j) + (r land 1);
                    loop (j + 1) (r lsr 1)
                )
            in
            loop 0 a
           )
    )
    in
    let rec loop shift acc mode =
        if shift < 0 then acc else (
            let mask = 1 lsl shift in
            if mode then (
                if k land mask = 0 then loop (shift - 1) acc mode else (
                    let p = count.(shift) in (* set *)
                    if n - p >= p then loop (shift - 1) (acc lor mask) mode
                                  else loop (shift - 1) acc false
                )
            ) else (
                let p = count.(shift) in (* set *)
                if n - p >= p then loop (shift - 1) (acc lor mask) mode
                              else loop (shift - 1) acc false
            )
        )
    in
    let x = loop 39 0 true in
    Array.fold_left (fun acc v -> acc + (x lxor v)) 0 a |> Printf.printf "%d\n"
)