def count_inner_bags_of(outer: str, rules: dict) -> int:
    """Recursively count all bags inside the outer one."""
    n_inner = sum(rules[outer].values())  # how many inside
    for inner, count in rules[outer].items():  # count bags inside the insides
        n_inner += count * count_inner_bags_of(inner, rules)
    return n_inner