import math


def compute_idfs(documents):
    """
    Given a dictionary of `documents` that maps names of documents to a list
    of words, return a dictionary that maps words to their IDF values.

    Any word that appears in at least one of the documents should be in the
    resulting dictionary.
    """
    idf = {}
    seen = set()
    docsets = {k: set(v) for k,v in documents.items()}
    for file, doc in documents.items():
        for word in doc:
            if word in seen:
                continue
            df = [1 if word in otherdoc else 0 for otherdoc in docsets.values()]
            df = sum(df)
            idf[word] = math.log(len(documents) / df)
            seen.add(word)

    return idf