Serge and Tanya want to show Masha a magic trick. Serge leaves the room. Masha writes down a sequence $(a_1, a_2, \ldots , a_n)$, where all $a_k$ equal $0$ or $1$. After that Tanya writes down a sequence $(b_1, b_2, \ldots , b_n)$, where all $b_k$ also equal $0$ or $1$. Then Masha either does nothing or says “Mutabor” and replaces both sequences: her own sequence by $(a_n, a_{n-1}, \ldots , a_1)$, and Tanya’s sequence by $(1 - b_n, 1 - b_{n-1}, \ldots , 1 - b_1)$. Masha’s sequence is covered by a napkin, and Serge is invited to the room. Serge should look at Tanya’s sequence and tell the sequence covered by the napkin. For what $n$ Serge and Tanya can prepare and show such a trick? Serge does not have to determine whether the word “Mutabor” has been pronounced.
1. **Claim**: The trick can be performed for all even \( n \).

2. **Construction for even \( n \)**:
   - Let \( n = 2k \).
   - Masha writes down a sequence \( (a_1, a_2, \ldots, a_n) \) where each \( a_i \) is either 0 or 1.
   - Tanya writes down a sequence \( (b_1, b_2, \ldots, b_n) \) where:
     \[
     b_i = \begin{cases} 
     a_i & \text{for } 1 \leq i \leq k \\
     1 - a_i & \text{for } k+1 \leq i \leq n 
     \end{cases}
     \]
   - Serge, upon seeing Tanya's sequence, will say:
     \[
     (b_1, b_2, \ldots, b_k, 1 - b_{k+1}, 1 - b_{k+2}, \ldots, 1 - b_n)
     \]
   - If Masha does not say "Mutabor", Tanya's sequence is:
     \[
     (a_1, a_2, \ldots, a_k, 1 - a_{k+1}, 1 - a_{k+2}, \ldots, 1 - a_n)
     \]
     and Serge will correctly identify Masha's sequence as:
     \[
     (a_1, a_2, \ldots, a_k, a_{k+1}, a_{k+2}, \ldots, a_n)
     \]
   - If Masha says "Mutabor", Tanya's sequence becomes:
     \[
     (1 - b_n, 1 - b_{n-1}, \ldots, 1 - b_{k+1}, b_k, b_{k-1}, \ldots, b_1)
     \]
     which is:
     \[
     (a_n, a_{n-1}, \ldots, a_{k+1}, 1 - a_k, 1 - a_{k-1}, \ldots, 1 - a_1)
     \]
     and Serge will correctly identify Masha's sequence as:
     \[
     (a_n, a_{n-1}, \ldots, a_1)
     \]

3. **Necessity for odd \( n \)**:
   - Suppose \( n = 2k + 1 \) is odd.
   - There are \( 2^n \) possible sequences for Masha and the same number for Tanya.
   - Each of Tanya's sequences must correspond to a unique Masha's sequence.
   - Consider Masha's sequence \( (0, 0, \ldots, 0) \).
   - If \( b_{k+1} = 0 \) and Masha says "Mutabor", \( b_{k+1} \) will become 1 while Masha's sequence remains \( (0, 0, \ldots, 0) \), leading to a contradiction.
   - Therefore, it is impossible to uniquely determine Masha's sequence for odd \( n \).

\(\blacksquare\)

The final answer is \( \boxed{ n } \) must be even.