import collections


def merge_dicts_resolve_collisions(**named_dicts):
    """
    Merge a collection of named dictionaries. Resolve collisions by prepending the dictionary name, i.e.
    '<dict name>__<original key>' to duplicate keys.

    Args:
        **named_dicts: Collection of named dictionaries to merge.

    Returns:
        The merged dictionary containing all key-value pairs of the input dictionaries, but collisions are resolved
        by renaming the duplicate keys.
    """
    key_frequencies = collections.Counter([key for dictionary in named_dicts.values() for key in dictionary])
    duplicate_keys = set(key for key, frequency in key_frequencies.items() if frequency > 1)

    return {
        f'{name}__{key}' if key in duplicate_keys else key: value
        for name, content in named_dicts.items() for key, value in content.items()
    }