New improved version for all permutations