Unofficial archive — problems, solutions & results © IMC, reproduced with permission.

IMC / 2026 / Problems / Day 1, P3

IMC 2026 · Day 1 · P3

hard

Consider a deck of n2n \geq 2 cards labeled 1,2,,n1, 2, \ldots, n. An alternating shuffle of the deck is performed as follows. We split the deck into two non-empty stacks. We then sort the first stack in increasing order, and the second stack in decreasing order. Finally, we alternately take cards from the first and second stacks (starting with the first). If one of the stacks runs out, the remaining cards from the other stack are placed at the end. How many different final orders of the deck can be obtained in this way?

Example: Suppose n=6n = 6, the first stack is A=(1,3)A = (1, 3), and the second stack is B=(6,5,4,2)B = (6, 5, 4, 2). Then the order resulting from the alternating shuffle is (1,6,3,5,4,2)(1, 6, 3, 5, 4, 2).

(proposed by Daniel Volostnov, Neapolis University Paphos, Cyprus)

Solution (official)

Setup. Define the reference string S=ABAB\mathcal{S} = A B A B \cdots of length nn. For a given subset YY of cards in the first stack, let SP{A,B}n\mathcal{S}_{P} \in \{ A, B \}^{n} be the source string of P(Y)P(Y): (SP)i=A\left( \mathcal{S}_{P} \right)_{i} = A if the card at position ii of PP came from deck AA, and (SP)i=B\left( \mathcal{S}_{P} \right)_{i} = B otherwise.

For i{1,2,,n}i \in \{ 1, 2, \ldots, n \}, define Bi={P(Y)the smallest index j with (SP)jSj equals i},B_{i} = \left\{ P(Y) \mid \text{the smallest index } j \text{ with } \left( \mathcal{S}_{P} \right)_{j} \neq \mathcal{S}_{j} \text{ equals } i \right\}, and let Bn+1={P(Y)SP=S}B_{n+1} = \left\{ P(Y) \mid \mathcal{S}_{P} = \mathcal{S} \right\} (i.e. the source string matches the reference string perfectly).

For each ii, let GiG_{i} be the directed graph on vertex set {1,2,,n}\{ 1, 2, \ldots, n \} where there is an edge from xx to yy whenever Px>PyP_{x} > P_{y}, encoding the relative-order structure common to all orders of BiB_{i}.

Throughout, assume i<ji < j.

Step 1. BiBj=B_{i} \cap B_{j} = \varnothing whenever jij - i is odd. Consider the graphs GiG_{i} and GjG_{j}, and look at vertices n1n-1 and nn. For ii and jj of different parity, the edge between n1n-1 and nn is directed in opposite ways in GiG_{i} and GjG_{j}. If a common order existed in BiBjB_{i} \cap B_{j}, it would simultaneously require Pn1>PnP_{n-1} > P_{n} and Pn1<PnP_{n-1} < P_{n}, a contradiction.

Step 2. BiBj=B_{i} \cap B_{j} = \varnothing whenever jij - i is even and ji>2j - i > 2. Consider the graphs GiG_{i} and GjG_{j} at vertices ii and i+2i+2. By the same argument as in Step 1, the edges between these vertices point in opposite directions, giving a contradiction.

Step 3. Bn+1B_{n+1} creates a single exceptional overlap with BnB_{n}. The set Bn+1B_{n+1} is on equal footing with the other BiB_{i}: Steps 1 and 2 apply to it as well, so Bn+1B_{n+1} is disjoint from all BiB_{i} except possibly Bn1B_{n-1} and BnB_{n} (by parity). In fact, Bn+1B_{n+1} and BnB_{n} share exactly one order: the sequence P=(1,n,2,n1,)P = (1, n, 2, n-1, \ldots) produced by A={1,2,,n/2}A = \{ 1, 2, \ldots, \lceil n / 2 \rceil \} and B={n,n1,,n/2+1}B = \{ n, n-1, \ldots, \lfloor n / 2 \rfloor + 1 \}. This is because the edge n1nn-1 \rightarrow n does not appear in Gn+1G_{n+1}, so the graph constraint of GnG_{n} is also satisfied. No other order of Bn+1B_{n+1} lies in BnB_{n}.

From Steps 1–3 it follows that B1B2Bn+1={P(Y):YS}B_{1} \cup B_{2} \cup \cdots \cup B_{n+1} = \{ P(Y) : Y \subseteq S \}, and the only non-empty pairwise intersections are Di:=BiBi+2D_{i} := B_{i} \cap B_{i+2} for i=1,,n1i = 1, \ldots, n-1, together with the single exceptional order BnBn+1=1\left| B_{n} \cap B_{n+1} \right| = 1.

Step 4. Computing Bi\left| B_{i} \right|. The graph GiG_{i} consists of two directed paths (“bamboo sticks”). Since each BiB_{i} encodes all possible subsets YY whose source string first deviates from S\mathcal{S} at position ii, the bamboo lengths depend on the parity of ii:

  • if ii is odd: Bi=(n(i1)/2)\left| B_{i} \right| = \binom{n}{(i-1) / 2},
  • if ii is even: Bi=(nni/2+1)\left| B_{i} \right| = \binom{n}{n - i / 2 + 1}.
Since all BiB_{i} together (for i=1,,n+1i = 1, \ldots, n+1) partition the set of source-string encodings of all 2n2^{n} subsets, we have i=1n+1Bi=2n.\sum_{i=1}^{n+1} \left| B_{i} \right| = 2^{n}.

Step 5. Computing the overlaps Di\left| D_{i} \right| where Di=BiBi+2D_{i} = B_{i} \cap B_{i+2}. From Steps 1 and 2, DiDj=D_{i} \cap D_{j} = \varnothing for iji \neq j. Consider the union graph GG^{\prime} of GiG_{i} and Gi+2G_{i+2}. For odd ii, the graph GG^{\prime} is almost identical to Gi+2G_{i+2} except that edges ii+1i \rightarrow i+1 and i+1i+2i+1 \rightarrow i+2 are added, which fix the relative order of (i+1)/2(i+1) / 2 vertices. Removing these determined vertices leaves two bamboo sticks, one with (i1)/2(i-1) / 2 vertices. Hence for odd ii, Di=(n(i+1)/2(i1)/2).\left| D_{i} \right| = \binom{n - (i+1) / 2}{(i-1) / 2}. Substituting i=2h+1i = 2 h + 1 gives Di=(n1hh)\left| D_{i} \right| = \binom{n - 1 - h}{h}.

An analogous argument for even i=2h+2i = 2 h + 2 yields Di=(n2hh)\left| D_{i} \right| = \binom{n - 2 - h}{h}.

Step 6. Assembling the answer. By inclusion–exclusion, N(n)=i=1n+1Bi1i=1n1Di,N(n) = \sum_{i=1}^{n+1} \left| B_{i} \right| - 1 - \sum_{i=1}^{n-1} \left| D_{i} \right|, where 1-1 accounts for the single exceptional overlap BnBn+1=1\left| B_{n} \cap B_{n+1} \right| = 1 from Step 3.

The sum of Bi\left| B_{i} \right| equals 2n2^{n} (Step 4).

The sum over odd-indexed DiD_{i} (i=1,3,5,i = 1, 3, 5, \ldots): when nn is odd this equals Fn1F_{n} - 1; when nn is even this equals FnF_{n}. Similarly, the sum over even-indexed DiD_{i} (i=2,4,6,i = 2, 4, 6, \ldots): when nn is odd this equals Fn1F_{n-1}; when nn is even this equals Fn11F_{n-1} - 1.

In both cases the total is i=1n1Di=Fn+Fn11=Fn+11.\sum_{i=1}^{n-1} \left| D_{i} \right| = F_{n} + F_{n-1} - 1 = F_{n+1} - 1.

Therefore, N(n)=2n1(Fn+11)=2nFn+1,\boxed{N(n) = 2^{n} - 1 - \left( F_{n+1} - 1 \right) = 2^{n} - F_{n+1}}, where Fn+1=Fn+Fn1F_{n+1} = F_{n} + F_{n-1} is the (n+1)(n+1)-th Fibonacci number (with F1=F2=1F_{1} = F_{2} = 1).

How the field did

contestants scored
412
average (of 10)
2.86
solved (≥ 80%)
18.0%
near-0 (≤ 10%)
56.3%
discrimination
0.17

Score distribution (field cohort)

Computed on contestants with a meaningful total (field cohort); discrimination is the corrected item–total correlation.

Similar problems

IMC 2007 · Day 1 · P4hardavg 2.0/10 · solved 16% · near-0 69% · disc 0.61
IMC 2001 · Day 2 · P9hardavg 2.3/10 · solved 16% · near-0 66% · disc 0.48
IMC 2022 · Day 2 · P6hardavg 3.1/10 · solved 21% · near-0 55% · disc 0.53
IMC 2015 · Day 2 · P8hardavg 2.3/10 · solved 21% · near-0 75% · disc 0.55
combinatorics