5. [5 points] A magician has a set of $15^{2}$ different cards. Each card has one side red and the other side blue; on each card, there is a natural number from 1 to 15 written on both sides. We will call a card a duplicate if the numbers on both sides of the card are the same. The magician wants to draw two cards such that at least one of them is a duplicate, and no number appears on both drawn cards simultaneously. In how many ways can he do this?
Answer: 2835.

Solution. Since the magician has a set of $15^{2}$ cards, all possible card variants exist (for each pair of numbers $(i ; j)$, where $1 \leqslant i \leqslant 15,1 \leqslant j \leqslant 15$, there is a card with the number $i$ written on the red side and $j$ on the blue side). Let's consider two types of card sets.

1) Both cards are duplicates. The number of ways to choose a pair of cards is

$$
C_{15}^{2}=\frac{15(15-1)}{2}=105
$$

2) Only one of the cards is a duplicate. Then it can be chosen in 15 ways, after which the second card can be chosen in any way except for: (a) all duplicates (15 in total, including the already chosen card), (b) all cards with the same number on the red side as the chosen duplicate (14 in total, excluding the chosen card), (c) all cards with the same number on the blue side as the chosen duplicate (also 14). Thus, the second card can be chosen in $15^{2}-15-14-14=182$ ways. Therefore, in this case, there are $15 \cdot 182=2730$ ways to choose a pair of cards.

Thus, there are $105+2730=2835$ ways in total.