I know how to get the number of derangements for a word that has no repeating letters for example "guitar":
$$6!\left(\frac{1}{0!}-\frac{1}{1!}+\frac{1}{2!}-\frac{1}{3!}+\frac{1}{4!}-\frac{1}{5!}+\frac{1}{6!}\right)$$
I also know how to get the number of derangements of a word with one set of repeating letters, such as "bottle", as this has been answered in another post.
However, when there are MULTIPLE sets of repeating letters, as in "MATHEMATICAL" (2 M's, 2 T's, and 3 A's), it becomes a bit more complicated considering if the first M is in the second M's place, according to the formula it's a derangement, but it actually is not. Could anyone help me out with this? Thanks!