let solve n = let len_n = String.length n in let rec count_hole' i result = if i >= len_n then result else let d = match n.[i] with | '0' | '4' |'6' |'9' -> 1 | '8' -> 2 | _ -> 0 in count_hole' (i + 1) (result + d) in let h_num = count_hole' 0 0 in min (len_n * 2 + 1 + h_num) ((1 + h_num) * 2 + len_n) let () = let n = read_line () in solve n |> string_of_int |> print_endline