<s>[INST] $6$-digit permutation problem How many $6$-digit different numbers greater than $400000$ can be formed from the digits $2$, $2$, $5$, $6$, $7$, $7$, $8$?
Note: $22$ and $77$ are allowed in the number. For instance, $622775$ is allowed.
My approach: $5$ ways to choose the first digit, $6$ ways to choose the second, $5$ ways to choose the third, $4$ ways to choose the fourth, $3$ ways to choose the fifth and $2$ ways to choose the sixth. So
the total arrangement is $5\times 6\times 5\times 4\times 3\times 2 = 3600$. But with the $2,2, 7, 7$ coming up, I think there is more do be done with it. I tried dividing $3600$ by  $(2! \times 2!)$. I tried this with a small number of digits and it gave the wrong answer. I am stuck. Can anyone help me with the answer or hint. Thanks
 [/INST] We apply generating function to the problem. First, we find how many 6-digit number can be formed from 2, 2, 5, 6, 7, 7, 8 starting with any digit. Notice that 2, 2, 7, 7, can appeal at most 2, which corresponds to $(1 + x + \frac{x^{2}}{2!})^{2}$. Also, 5, 6, 8 can appeal at most 1, which corresponds to $(1 + x)^{3}$. Now find the coefficient of     $\frac{x^{6}}{6!}$ in the product  $(1 + x + \frac{x^{2}}{2!})^{2}(1 + x)^{3} = \frac{x^{7}}{4} + \frac{7x^{6}}{4} + \frac{23x^{5}}{4} + \frac{45x^{4}}{4} + 14x^{3} + 11x^{2} + 5x + 1$, which is $\frac{6! \times 7}{4} = 1260$.
Next, find the 6-digit numbers that begin with 2. In that case, 5 slots to fill using 2, 5, 6, 7, 7, 8. Again, 7, 7, can appeal at most 2 giving $(1 + x + \frac{x^{2}}{2!})$ and 2, 5, 6, 8 can appeal at most 1 giving (1 + x)^{4}. Since the have 5 choices, we find the coefficient of $\frac{x^{5}}{5!}$  in the product $(1 + x + \frac{x^{2}}{2!})(1 + x)^{4} = \frac{x^{6}}{2} + 3x^{5} + 8x^{4} + 12x^{3} + \frac{21x^{2}}{2} + 5x + 1$, which is $5! \times 3 = 360$.
Finally, the 6-digit number can't start with 2, and hence total number of arrangement is $1260 -360 = 900$ ways.
</s>