def transition_model(corpus, page, damping_factor):
    """
    Return a probability distribution over which page to visit next,
    given a current page.

    With probability `damping_factor`, choose a link at random
    linked to by `page`. With probability `1 - damping_factor`, choose
    a link at random chosen from all pages in the corpus.
    """
    pagePointers = set()
    for x, y in corpus.items():
        if x == page:
            pagePointers = y
            break

    chances = dict()
    if len(pagePointers) == 0:
        chance = 1/len(corpus)
        for x in corpus:
            chances[x] = chance
        return chances

    chanceAmortecimento = (1-damping_factor)/(len(corpus))
    chanceComum = (damping_factor/len(pagePointers))
    for x in corpus:
        if x in pagePointers:
            chances[x] = chanceAmortecimento + chanceComum
        else:
            chances[x] = chanceAmortecimento

    return chances