# Given 5 different balls and 5 different boxes, in how many ways can you put the balls in the boxes such that at most 3 boxes are empty?

My answer: As, at least 2 boxes should be not empty, we need to have 2 boxes with one ball each. No of ways in which we can do that is $$\binom52^22$$ (ways of choosing 2 balls * ways of choosing 2 boxes * ways of placing the chosen balls in the box). We will have 3 balls remaining, which can be placed in $$5^3$$ ways. $$2\binom525^3= 8×5^5$$ But the given answer is $$5^5 - 5$$. Where did I go wrong?

Obviously the answer cannot be greater than $$5^5$$, the number of ways to put the balls in the boxes without restrictions. Now the only way to have more than 3 boxes empty is to have 4 empty and the remaining box having all the balls, which can occur in 5 ways, hence the given correct answer of $$5^5-5$$.