processing permutations with repetitions