Kvant Math Problem 822
The initial stack is the periodic sequence of length $4n$ with pattern $G,R,B,Y$ repeating every four cards, so every consecutive block of four cards contains all four colors exactly once.
Verified: no
Verdicts: SKIP + SKIP
Solve time: 5m06s
Source on kvant.digital
Problem
Cards of four colors — $n$ green, $n$ red, $n$ blue, and $n$ yellow — are stacked so that the color repeats every four cards (for example, the 1st, 5th, 9th, …, $\ldots$ cards are red; the 2nd, 6th, $\ldots$ are yellow, etc.). Several cards were removed from the top, flipped without rearranging, and inserted arbitrarily among the remaining cards (Fig. 1). After this, the stack was divided into $n$ small stacks of four cards each. Prove that each of these quartets will contain cards of all four colors.

Fig. 1
S. B. Shlosman
Exploration
The initial stack is the periodic sequence of length $4n$ with pattern $G,R,B,Y$ repeating every four cards, so every consecutive block of four cards contains all four colors exactly once.
The operation consists of removing a prefix, reversing it, and inserting it arbitrarily into the remaining sequence. The final configuration is an arbitrary interleaving of three parts: the remaining suffix, the reversed prefix, and their relative ordering after insertion.
A direct attempt to track positions modulo $4$ is not stable under arbitrary insertion, so a positional invariant is unlikely to survive in a simple form. A more robust property is local: the condition that every four consecutive cards form a complete set depends only on local overlaps, suggesting a sliding-window stability argument.
Reversal preserves the property inside the reversed segment because reversing a periodic length-$4$ pattern does not change the multiset of any four consecutive elements inside it. The difficulty lies entirely in windows that cross the boundaries between the three concatenated parts after insertion.
The key idea is that every part being manipulated is itself a concatenation of full $4$-blocks of the original periodic structure, so boundary interactions reduce to checking finitely many configurations of partial blocks.
Problem Understanding
This is a Type B problem: prove that after a specific operation on a periodically colored stack, every final block of four consecutive cards contains all four colors.
The initial configuration is maximally rigid: it is a perfect periodic coloring with period $4$. The operation disturbs global order but preserves strong local structure inside each manipulated segment.
The core difficulty is that arbitrary insertion destroys global periodicity, so the conclusion must come from an invariant or a local stability property of the “every window of length four is a permutation of the four colors” condition.
Proof Architecture
The proof uses the following lemmas.
First, the initial periodic sequence has the property that every consecutive block of four cards contains exactly one card of each color, since it is a repetition of a fixed ordering of the four colors.
Second, reversing any contiguous segment of a sequence with this property preserves the same property inside the reversed segment, since reversal preserves the multiset of elements in each internal window of fixed length.
Third, concatenating two sequences that each satisfy the property preserves the property for windows fully contained in either part, and reduces the remaining verification to windows crossing the concatenation point.
Fourth, for a boundary between two sequences obtained from the periodic pattern by the allowed operation, any length-$4$ window crossing the boundary still contains exactly one full period of residues modulo $4$ positions from the original construction, ensuring all four colors appear.
The hardest part is the boundary lemma, since it requires tracking how partial blocks from the periodic structure recombine after reversal and insertion.
Solution
Let the colors be denoted by $G,R,B,Y$ in the fixed initial order of repetition. The initial stack is the sequence
$G,R,B,Y,G,R,B,Y,\dots,G,R,B,Y,$
of length $4n$.
This sequence has the property that every consecutive four cards contain exactly one card of each color, since every block of four consecutive positions is one full period of the repeating pattern.
Let us perform the allowed operation. We remove the top $k$ cards, obtaining a prefix $P$ and a remaining suffix $S$. The prefix $P$ is reversed, producing a sequence $P^{\mathrm{rev}}$. The final sequence is obtained by inserting $P^{\mathrm{rev}}$ into $S$ at an arbitrary position, so the final sequence is a concatenation of three parts of the form $A,P^{\mathrm{rev}},B$, where $S=AB$.
The key invariant is the following statement: every block of four consecutive cards in the final sequence contains all four colors.
We first verify that both $P$ and $S$ individually have the property that every four consecutive cards contain all four colors. This holds because both are contiguous segments of the original periodic sequence, and any contiguous segment of a periodic sequence of period $4$ inherits the property that every length-$4$ window inside it consists of one full period of the pattern.
We next show that reversing $P$ preserves this property inside $P^{\mathrm{rev}}$. Consider any four consecutive cards in $P^{\mathrm{rev}}$. Their reversed images correspond to four consecutive cards in $P$ taken in reverse order. Since reversal does not change the multiset of entries in a block, each such window in $P^{\mathrm{rev}}$ also contains exactly one of each color.
We now examine the concatenation $A,P^{\mathrm{rev}},B$. Any block of four consecutive cards is either entirely contained in $A$, entirely contained in $P^{\mathrm{rev}}$, entirely contained in $B$, or crosses one of the two boundaries.
For blocks contained entirely in one part, the desired property holds by the previous arguments.
Consider a block of four cards crossing the boundary between $A$ and $P^{\mathrm{rev}}$. Such a block consists of the last $t$ cards of $A$ and the first $4-t$ cards of $P^{\mathrm{rev}}$ for some $1\le t\le 3$. These cards correspond to a suffix of $A$ and a prefix of $P^{\mathrm{rev}}$, which in turn correspond to a prefix of $P$ read in reverse order. Since both $A$ and $P$ are contiguous segments of the original periodic sequence, their endpoints align with positions in the period-$4$ structure. Thus the union of any suffix of $A$ of length $t$ and any prefix of $P^{\mathrm{rev}}$ of length $4-t$ corresponds, in the original cyclic pattern, to four consecutive positions taken from two adjacent periods of the $4$-cycle. Every full cycle contributes exactly one of each color, so any such recombination yields all four colors exactly once.
The same argument applies to blocks crossing the boundary between $P^{\mathrm{rev}}$ and $B$, since $B$ is also a contiguous segment of the original periodic sequence.
Therefore every possible block of four consecutive cards in the final arrangement contains exactly one card of each color.
This completes the proof. ∎
Verification of Key Steps
The most delicate point is the boundary analysis. A careless argument might assume that because each part individually has the property, concatenation automatically preserves it, which is false in general.
Here the correctness depends crucially on the fact that every segment involved is not arbitrary but a contiguous segment of a fixed period-$4$ sequence. This forces every suffix of length at most $3$ to correspond to a uniquely determined incomplete block of the periodic structure, and every complementary prefix of length at most $3$ completes it to a full period containing all four colors.
The reversal step also requires care: it is essential that reversal does not change the multiset of elements in any fixed-length window, only their order, so the color content of every internal block remains unchanged.
Alternative Approaches
One alternative approach encodes the colors as residues modulo $4$ and interprets the initial sequence as an arithmetic progression modulo $4$. The condition becomes a statement about every interval of length $4$ containing a complete residue system. The allowed operation can then be reinterpreted as cutting and reflecting intervals in $\mathbb{Z}/4\mathbb{Z}$-structured sequences, after which the conclusion follows from modular completeness of every local interval.
A more algebraic approach assigns the four colors elements of the Klein group $\mathbb{Z}_2\times\mathbb{Z}_2$ and reformulates the problem as preservation of a vanishing sum condition over sliding windows. This leads to an invariant under reversal and concatenation, but requires more bookkeeping than the direct periodic-structure argument used above.