Mohammed has eight boxes numbered 1 to 8 and eight balls numbered 1 to 8 . In how many ways can he put the balls in the boxes so that there is one ball in each box, ball 1 is not in box 1 , ball 2 is not in box 2 , and ball 3 is not in box 3 ?
(A) 27240
(B) 29160
(C) 27360
(D) 27600
(E) 25200
If we have $n$ balls to be placed in $n$ boxes, one per box and without restriction, then there are $n !=n(n-1)(n-2) \cdots(3)(2)(1)$ ways to do this. (This is because there are $n$ choices for the ball to placed in box 1 ; for each of these, there are $n-1$ choices for the ball to be placed in box 2 ; for each of these pairs of choices, there are $n-2$ choices for the ball to be placed in box 3 , and so on. In total, there are $n(n-1)(n-2) \cdots(3)(2)(1)$ ways to do this.)

We draw a Venn diagram where $S$ represents all of the ways of placing the 8 balls in 8 boxes without restriction, circle $A$ represents the ways in which the balls are placed with ball 1 going in box 1 , circle $B$ represents the ways with ball 2 going in box 2, and circle $C$ represents the ways with ball 3 going in box 3 .

![](https://cdn.mathpix.com/cropped/2024_04_20_33a8a6559d675f59baa2g-118.jpg?height=441&width=526&top_left_y=674&top_left_x=859)

Here, $s$ represents the number of ways of putting the balls in boxes so that ball 1 is not in box 1 ( $s$ is outside circle $A$ ), ball 2 is not in box 2 ( $s$ is outside circle $B$ ), and ball 3 is not in box 3 ( $s$ is outside circle $C$ ). We want to calculate $s$.

The total number of ways in $S$ is 8 !.

Circle $A$ represents the ways when ball 1 is in box 1, and the other 7 balls are placed without restriction. There are 7 ! such ways.

Similarly, the number of ways inside each of circle $B$ and circle $C$ is 7 !.

In other words, $t+w+y+z=u+w+x+z=v+x+y+z=7$ !.

The overlap between circle $A$ and $B$ represents the ways with ball 1 in box 1 and ball 2 in box 2 , with the other 6 balls placed without restriction. There are 6 ! such ways.

Similarly, there are $6 !$ ways in the intersection of circles $A$ and $C$, and circles $B$ and $C$.

In other words, $w+z=y+z=x+z=6$ !.

Finally, the intersection of all three circles represents the ways in which ball 1 is in box 1 , ball 2 is in box 2 , ball 3 is in box 3 , and the other 5 balls are placed without restriction. There are 5 ! such ways.

In other words, $z=5 !$.

Since $z=5 !$, then $w=x=y=6 !-5 !$.

Futhermore, $t=u=v=7 !-2(6 !-5 !)-5 !=7 !-2(6 !)+5 !$.

Finally,

$$
\begin{aligned}
s & =8 !-(t+u+v+w+x+y+z) \\
& =8 !-3(7 !-2(6 !)+5 !)-3(6 !-5 !)-5 ! \\
& =8 !-3(7 !)+6(6 !)-3(5 !)-3(6 !)+3(5 !)-5 ! \\
& =8 !-3(7 !)+3(6 !)-5 !
\end{aligned}
$$

Now, $5 !=5(4)(3)(2)(1)=120$ so $6 !=6(5 !)=6(120)=720$ and $7 !=7(6 !)=7(720)=5040$ and $8 !=8(7 !)=8(5040)=40320$.

Therefore, $s=40320-3(5040)+3(720)-120=27240$.

Thus, the number of ways of putting the balls in the boxes with the given restrictions is 27240 .

We note that an alternative way of performing the algebraic steps is as follows:

$$
\begin{aligned}
s & =8 !-(t+u+v+w+x+y+z) \\
& =8 !-(t+w+y+z)-(u+w+x+z)-(v+x+y+z)+w+x+y+2 z \\
& =8 !-(t+w+y+z)-(u+w+x+z)-(v+x+y+z)+(w+z)+(x+z)+(y+z)-z \\
& =8 !-7 !-7 !-7 !+6 !+6 !+6 !-5 ! \\
& =8 !-3(7 !)+3(6 !)-5 !
\end{aligned}
$$

which leads to the same final answer.

ANSWER: (A)