4. Before leaving for work, Mom entrusted Misha, Petya, and Vasya with the following tasks: a) sweep the floor in the hallway; b) wash the dishes; c) buy bread; d) pay for electricity; e) take out the trash; f) vacuum the carpet in the living room. In how many different ways can they distribute the tasks so that each task is done by one of the boys and each of them does something?
Answer: 540.

Solution: There are a total of $3^{6}=729$ ways to distribute the tasks. However, in $2^{6}=64$ ways, all tasks will be performed by Misha and Petya. There are also 64 ways when all tasks will be performed by Petya and Vasya, and 64 ways when Misha and Vasya. If we subtract $3 \times 64$, we get that the cases where one person does all the work have been subtracted twice. Therefore, add $3: 3^{6}-3 \cdot 2^{6}+3=540$.