use sorted and permutation from standard library.