you give permutation number 12n m pair position ajbjAt step choose pair give position swap number position what lexicographically maximal permutation getLet p q permutation number 12n p lexicographically small q number 1 in exist pkqk 1ki piqi