Scanf.scanf "%s" (fun n -> let hist = Array.make 8 0 in let il x = String.index "ABCDEF" x + 10 in let rec loop i m = if i >= 0 then ( let k = match m with | 0 -> (il n.[i]) land 7 | 1 -> (((il n.[i]) land 3) lsl 1) lor (((il n.[i + 1]) lsr 3) land 1) | 2 -> (((il n.[i]) land 1) lsl 2) lor (((il n.[i + 1]) lsr 2) land 3) | _ -> (il n.[i]) lsr 1 in hist.(k) <- hist.(k) + 1; loop (if m = 2 then i else i - 1) ((m + 1) mod 4) ) else ( let q = match m with | 1 -> ((il n.[i + 1]) lsr 3) land 1 | 2 -> ((il n.[i + 1]) lsr 2) land 3 | _ -> -1 in if q >= 0 then hist.(q) <- hist.(q) + 1 ) in loop (String.length n - 1) 0; let rec loop i mx mxl = if i = 8 then mxl else if hist.(i) > mx then loop (i + 1) hist.(i) [ i ] else if hist.(i) = mx then loop (i + 1) hist.(i) (i :: mxl) else loop (i + 1) mx mxl in let l = loop 0 0 [] in List.iter (Printf.printf "%d ") @@ List.rev l; print_newline () )