Basically, I am first calculating how many different ways there are to put the 4 S's and I's in any order and with a certain number of repeats. Then I am multiplying each by the number of ways each allows for putting 2 P's and an M to end with no repeated letters.
There are 2 ways to write the S's and I's with no repeats (one is 'SISISISI'

. For each of these ways there are then 405 ways to add the M and P's (for example 'SPIPSISMISI'

.
There are 6 ways to write them with one repeat (one is 'SISIISIS'

. For each of these ways there are then 117 ways to add the M and P's (for example 'SPIPSIMISIS'

. There are a lot fewer ways because you have to separate the repeated letters.
There are 18 ways to write them with two repeats, but each of these only leaves 25 ways to place the M and P's.
Finally, there are 18 ways to write them with three repeats, which only leaves 3 ways to place the M and P's.
If you write them with more than three repeats, the M and P's can't be placed.
Thus the total number of ways is 2*405 + 6*117 + 18*25 + 18*3. There are details about how I calculated each of those eight numbers in the original post (repeated below). C refers to the choose function: nCk = n!/(k!(n-k)!).
I hope this is helpful.
Jonathan Dushoff
(I earlier wrote the following
