import collections


def flip(containers):
    """
    Invert the input so that instead of representing the containers, we
    represent the bags that can be contained in each container.
    """

    contents = collections.defaultdict(set)
    for container in containers:
        for content in containers[container]:
            contents[content].add(container)

    return contents