let group_by cmp lst = let rec hdsplit hdval lst (lst1, lst2) = if lst = [] then (lst1, lst2) else match cmp (List.hd lst) with | v when v = hdval -> hdsplit hdval (List.tl lst) ((List.hd lst):: lst1, lst2) | _ -> hdsplit hdval (List.tl lst) (lst1, (List.hd lst):: lst2) in let rec make_result lst result = match lst with | [] -> result | x::xs -> let lst1, lst2 = hdsplit (cmp x) lst ([], []) in make_result lst2 ((cmp x, lst1)::result) in make_result lst [] let judge_eto (lst: string list) = let glst = group_by (fun id -> id) lst in let rec get_max_length lst result = match lst with | [] -> result | x::xs -> let maxVal = max (List.length x) result in get_max_length xs maxVal in let elst = glst |> List.map (fun (_, lst) -> lst) in let mlen = get_max_length elst 0 and ilen = List.length lst in int_of_float (ceil ((float_of_int ilen) /. 2.)) >= mlen let () = let n = read_int () and elst = ref [] in for i = 1 to n do let line = read_line () in elst := line :: !elst done; (!elst) |> judge_eto |> (function | true -> "YES" | false -> "NO") |> (Printf.printf "%s\n")