let rec group xs = match xs with | [] -> [] | x :: rest -> let rec collect cur acc tail = match tail with | [] -> (List.rev acc, []) | y :: ys -> if y = cur then collect cur (y :: acc) ys else (List.rev acc, y :: ys) in let (g, tail) = collect x [x] rest in g :: group tail ;; let gs = group [1;1;2;2;2;3;1;1;4] in List.length gs * 10 + List.length (List.nth gs 1)