def required_bags(bag: str, count: int, rules: dict[str, list]) -> int:
    """Returns the total amount of bags required to fit `bag` into bag,
    following the given `rules`.

    Note: Return includes the top `bag`(s), subtract the return value
    by `count` to get total bags needed inside of the parent bag.
    """
    return count + sum(required_bags(bcolor, bcount, rules) * count
                       for bcount, bcolor in rules[bag])