Source: IMO-2008-P5
Category: Counting

Problem:
Let $n$ and $k$ be positive integers with $k \ge n$ and $k-n$ an even number. There are $2n$ lamps labelled $1,2,\dots,2n$ each of which can be either on or off. Initially all the lamps are off. We consider sequences of steps: at each step one of the lamps is switched (from on to off or from off to on). Let $N$ be the number of such sequences consisting of $k$ steps and resulting in the state where lamps $1$ through $n$ are all on, and lamps $n+1$ through $2n$ are all off. Let $M$ be the number of such sequences consisting of $k$ steps, resulting in the state where lamps $1$ through $n$ are all on, and lamps $n+1$ through $2n$ are all off, but where none of the lamps $n+1$ through $2n$ is ever switched on. Determine $\frac{N}{M}$.

Solution:
The answer is $2^{k-n}$.

Consider the following map $\Psi$ from the set of $N$-sequences to the set of $M$-sequences: for each $i \in \{1, 2, \dots, n\}$, change every instance of a switch of lamp $n+i$ to a switch of lamp $i$. (For example, suppose $k=9$ and $n=3$; then the sequence $1, 4, 4, 2, 2, 5, 2, 5, 3$ maps to $1, 1, 1, 2, 2, 2, 2, 2, 3$.)

To see that this map is well-defined, note that for any $N$-sequence, the total number of times lamps $i$ and $n+i$ are switched is $a_i + b_i$, where $a_i$ is odd (since lamp $i$ ends up on) and $b_i$ is even (since lamp $n+i$ ends up off). Thus, the number of times lamp $i$ is switched in the image sequence is $c_i = a_i + b_i$, which is the sum of an odd and an even integer, and hence is odd. This means that in the image sequence, lamp $i$ ends up on. Furthermore, lamps $n+1$ through $2n$ are never switched in the image sequence, meaning they remain off. Therefore, the image is indeed an $M$-sequence. The map is clearly surjective, as any $M$-sequence is its own image.

**Claim:** Every $M$-sequence has exactly $2^{k-n}$ pre-images under $\Psi$.

*Proof.* Let an $M$-sequence be given. Suppose that for each $i \in \{1, 2, \dots, n\}$, there are $c_i$ instances of lamp $i$ being switched in this sequence. As established, $c_i$ must be an odd positive integer because lamp $i$ ends up on. To reconstruct a pre-image under $\Psi$, we must choose which of the $c_i$ switches of lamp $i$ were originally switches of lamp $n+i$. Since lamp $n+i$ must end up off in the $N$-sequence, it must have been switched an even number of times. Thus, we need to pick an even subset of the $c_i$ switches to change to $n+i$. 

Since $c_i \ge 1$, the number of ways to choose an even subset from a set of size $c_i$ is exactly $2^{c_i-1}$. This choice can be made independently for each $i \in \{1, 2, \dots, n\}$. Hence, the total number of pre-images for the given $M$-sequence is the product of the number of choices for each $i$:
\[
\prod_{i=1}^n 2^{c_i-1} = 2^{\sum_{i=1}^n (c_i - 1)} = 2^{k-n},
\]
where we used the fact that the total number of steps is $\sum_{i=1}^n c_i = k$.

Since every $M$-sequence has exactly $2^{k-n}$ pre-images under $\Psi$, it follows that $N = 2^{k-n} M$. Therefore, the ratio $\frac{N}{M}$ is $2^{k-n}$.

Answer: $2^{k-n}$

Grading guidelines:
(Partial) 1. Used the parity condition to note that in any valid sequence the number of switches of lamp i (1<=i<=n) is odd, and the number of switches of lamp n+i is even. 2. Defined (or effectively used) the map that replaces every switch of lamp n+i by a switch of lamp i, and checked that the image sequence never switches lamps n+1,...,2n and ends with lamps 1,...,n on. 3. Observed that for a fixed M-sequence with c_i occurrences of lamp i, the number of ways to choose which of these occurrences came from lamp n+i is the number of even-size subsets of {1,...,c_i}. (Almost) 1. Obtained the correct preimage count 2^(c_i-1) for each i and multiplied to get 2^(k-n), but did not clearly justify either independence over i or the identity sum c_i=k. 2. Set up the surjection Psi and the even-subset reconstruction, and concluded N/M=2^(k-n), but left a minor gap in proving that every preimage indeed ends with lamps n+1,...,2n off (i.e., that the chosen subsets must be even and this is sufficient). 3. Solution is almost complete, but made minor mistakes which are not negligible.