Scanf.scanf "%d %d" (fun n m ->
    let hist = Array.make 100001 0 in
    let modgrp = Array.make m 0 in
    for i = 1 to n do
        Scanf.scanf " %d" (fun x ->
            hist.(x) <- hist.(x) + 1;
            modgrp.(x mod m) <- modgrp.(x mod m) + 1;
        )
    done;
    let modpar = Array.make m 0 in
    Array.iteri (fun i x -> modpar.(i mod m) <- modpar.(i mod m) + x / 2) hist;
    let calc1 i = modgrp.(i) / 2 in
    let calc2 i j =
        let i, j = if modgrp.(i) <= modgrp.(j) then i, j else j, i in
        let rest = (modgrp.(j) - modgrp.(i)) / 2 in

        modgrp.(i) + min rest modpar.(j)
    in
    let rec loop i acc =
        if i * 2 > m then acc else
            let acc = if i = 0 || i * 2 = m then acc + calc1 i
                                            else acc + calc2 i (m - i)
            in
            loop (i + 1) acc
    in
    loop 0 0 |> Printf.printf "%d\n"
)