This finds the rank and permutations of a multiset.