PLEASE CLARIFY THE QUESTION

https://www.codechef.com/problems/DEVHAND.

In this problem, can anyone explain the prefix part ( especially how the last output is coming 36).

See all the arrangements will be

a b aa bb ab ba

aa bb ab * 3!

bb ab ba * 3!

ab ba aa * 3!

ba aa bb * 3!

a bb ba * 3!

b aa ab * 3!

I have written 3! in front of every combination because say you got the 3 required strings and so to distribute it to into 3 people you have 3 x 2 x 1 choices.

And the prefix thing means that say you have 3 picked up 3 strings p , q and r then these strings should be chosen in such a way that there is not string which is a prefix of another.

In the above case i cant pick “a” , “aa” and “ba” together because “a” is a prefix of “aa” and itself is one of the chosen strings which violates the condition

//