# Shuffled Safe Codes: Solution

*English translation by SOTA – AI Community of the Russian original. Organisers who would like this translation removed can email sota.ai.community@gmail.com.*

*Task 1 of the school stage of the All-Russian School Olympiad (VsOSh) 2025/26 in artificial intelligence (region group I), grades 9–11. Answer and official solution.*

**Answer:** $\frac{5}{8}$

**Solution.**

There are $4! = 24$ permutations of the four labels in total.

Let us count in how many permutations at least one code stays in its place. To do this, we use the inclusion–exclusion principle.

**1. First, we count all permutations in which at least one code is in its place.** We can choose which code stays — 4 ways. The remaining 3 codes can be permuted in any way — $3! = 6$ ways. In total, $4 \times 6 = 24$ permutations.

**2. But this counts too much.** If two codes are in place at once, such a permutation has been counted twice — once when the first code was chosen and once when the second was chosen. To correct this, we subtract the number of permutations in which *exactly two* codes are in place: we choose these two codes — 6 ways, and the remaining two can be permuted in $2! = 2$ ways. We subtract $6 \times 2 = 12$.

**3. But now we have subtracted too much.** If three codes are in place at once, we subtracted such permutations three times, whereas only two subtractions were needed, so we must add them back: we choose these three codes (4 ways), and the last code is left on its own — $1!$ way. We add $4 \times 1 = 4$.

**4. Finally, when all four are in place,** we added such a permutation four times, then subtracted it six times and added it four times again — so in total it has been counted three times. To correct this, we subtract one repetition: $1 \times 0! = 1$.

Now we add everything up, taking the signs into account:

$$24 - 12 + 4 - 1 = 15.$$

That is, there are 15 permutations in which at least one code has stayed in place.

There are 24 permutations in total, so the probability is

$$P = \frac{15}{24} = \frac{5}{8}.$$
