Scanf.scanf "%d %d %d" (fun n a b ->
    let p = Array.init n (fun _ -> Scanf.scanf " %d" (fun p -> p)) in

    let rec loop i cat1 cat2 cat3 =
        if i = n then min (min cat1 cat2) cat3 else
            if p.(i) <= a then loop (i + 1) (cat1 + 1) cat2 cat3 else
            if p.(i) <= b then loop (i + 1) cat1 (cat2 + 1) cat3 else
                               loop (i + 1) cat1 cat2 (cat3 + 1)
    in
    Printf.printf "%d\n" @@ loop 0 0 0 0
)