sort by permutation