def get_bags_contained(rules, color):
    """ Counts the bags that are in the specified bag.

    Solved with recursion.
    :param rules: rules
    :param color: color of bag
    :return: int
    """
    counter = 0

    # if no bags contained return 0
    if rules[color] is None:
        return counter

    # iterate over bags that are directly in the current bag
    for bag, count in rules[color].items():
        # add amount of that bag
        counter += count
        # add amount of that bag * bags in that bag
        counter += count * get_bags_contained(rules, bag)

    return counter