def perm_cycle_type(p, n=None):
    """
    Return the lengths of the cycles of the permutation ``p`` in size of
    decreasing order.

    EXAMPLES::

        sage: from surface_dynamics.misc.permutation import perm_cycle_type
        sage: perm_cycle_type([1,2,3,0])
        [4]
        sage: perm_cycle_type([0,2,3,1])
        [3, 1]
        sage: perm_cycle_type([3,2,1,0])
        [2, 2]
        sage: perm_cycle_type([3,1,2,0])
        [2, 1, 1]
        sage: perm_cycle_type([0,1,2,3])
        [1, 1, 1, 1]
    """
    if n is None:
        n = len(p)
    seen = [False] * n
    c = []
    for i in range(n):
        if seen[i] or p[i] == -1:
            continue
        k = 0
        j = i
        while not seen[j]:
            seen[j] = True
            k += 1
            j = p[j]
        c.append(k)
    c.sort(reverse=True)
    return c
