def cycle_to_permut(cycle,n):

    p = [0] * n

    for i in range(n):

        if i+1 in cycle:

            if cycle.index(i+1) == len(cycle) - 1:

                p[i] = cycle[0]

            else:

                p[i] = cycle[ cycle.index(i+1) + 1 ]

        else:

            p[i] = i+1

    return p



def permut(liste,p):

    L = [0] * len(liste)

    for i in range(len(liste)):

        L[i] = liste[ p[i] - 1 ]

    return L