A word is a finite sequence of letters from some alphabet. A word is repetitive if it is a concatenation of at least two identical subwords (for example, $ababab$ and $abcabc$ are repetitive, but $ababa$ and $aabb$ are not). Prove that if a word has the property that swapping any two adjacent letters makes the word repetitive, then all its letters are identical. (Note that one may swap two adjacent identical letters, leaving a word unchanged.) Romania (Dan Schwarz)
Problem
Source: 2012 European Girls’ Mathematical Olympiad P8
Tags: modular arithmetic, combinatorics, EGMO, EGMO 2012, complex numbers
14.04.2012 19:33
http://www.artofproblemsolving.com/Forum/viewtopic.php?p=2378873&sid=49913b482ab96c41a264582ec5d59ea8#p2378873
16.04.2012 06:38
Suppose the word ($W$) has $n$ letters. For $n\le 6$ the problem is easy to verify (trivial for primes), so we can assume $n\ge7$. If a word has period $d$ (i.e. if it is a concatenation of $n/d$ identical subwords), call it $d$-periodic (of course, $d\mid n$). Let $a_k$ be the $k^{th}$ letter from the left (for $1\le k\le n$) and $f(k)\le n/2$ (for $1\le k\le n-1$) denote the smallest $d<n$ such that $W$ is $d$-periodic upon switching $a_k$ and $a_{k+1}$. For convenience, extend indices modulo $n$ (this is compatible with the period condition). If $f(k)=1$ for some $k$, the problem is trivial, so suppose that $f(k)\ge 2$ for all $k$. First observe that if $a_k=a_{k+1}$, then $W$ is $f(k)$-periodic itself. Lemma: $a_{k-1}=a_{k+1}$ for $2\le k\le n-1$. Proof: If $\max(f(k-1),f(k))<n/2$, then using the condition when $a_{k-1},a_k$ are swapped yields $a_{k-1}=a_{k+f(k-1)}$ (since $k+f(k-1)\notin\{k-1,k\}\pmod{n}$) and $a_{k+f(k)}=a_{k+f(k)+f(k-1)}$ (since $k+f(k),k+f(k)+f(k-1)\notin\{k-1,k\}\pmod{n}$, where we use the fact that $f(k)+f(k-1)\le n/2+n/3=5n/6<n-1$). Similarly, using the condition when $a_k,a_{k+1}$ are swapped yields $a_{k+1}=a_{k+f(k)}$ (since $k+f(k)\notin\{k,k+1\}\pmod{n}$) and $a_{k+f(k-1)}=a_{k+f(k-1)+f(k)}$ (since $k+f(k-1),k+f(k-1)+f(k)\notin\{k,k+1\}\pmod{n}$, where we use the fact that $f(k)+f(k-1)<n-1<n$). Thus \[a_{k-1}=a_{k+f(k-1)}=a_{k+f(k-1)+f(k)}=a_{k+f(k)+f(k-1)}=a_{k+f(k)}=a_{k+1},\]so we're done in this case. Otherwise, $f(k-1)=f(k)=n/2$, so because $n/2\ge3$, $\{k-1,k,k+1\}\cap\{k-1+n/2,k+n/2,k+1+n/2\}\pmod{n}=\emptyset$. Thus $a_{k-1}=a_{k+n/2}=a_{k+1}$ from the $a_{k-1},a_k$ and $a_k,a_{k+1}$ swaps, as desired.$\blacksquare$ In light of the lemma, set $a=a_1=a_3=\cdots$ and $b=a_2=a_4=\cdots$, and suppose that $a\ne b$. Swapping $a_1$ and $a_2$, we see that there must be at least two disjoint sets of consecutive $a$'s, contradiction.
23.04.2012 21:28
There's a very nice solution instantly killing this problem, but I think that such a tricky solution wasn't required, because thesis looks like it could be achieved by writing many small letters and playing with many cases. Let's assume that our word is periodic. The opposite is pretty easy (not really obvious, but a periodic case is more interesting). Change every letter into a real number (change letters to the same number iff they are the same) and define $\omega=e^{\frac{2 \pi i}{n}}$, where $n$ is lenght of our word and define ${W=\sum_{i=1}^n}w_i \omega^{i-1}$, where $w_i$ denotes $i$-th number in our word. One can see that $W=0$ since our word is periodic. But if we swap to adjacent different letter, we will change $W$, thus new word won't be periodic .
24.04.2012 09:44
To paul1703, the link you give treats the case when any two consecutive letters are different; that requirement is missing in the EGMO problem, and makes it quite more difficult. So Swistak's solution reduces the problem to precisely this case when any two consecutive letters are different, since if some two consecutive are identical, their swap will leave the word unchanged, thus repetitive. There is a short solution, like the one in the link provided by paul1703 (but not completely trivial). A much harder problem is to allow only swaps between consecutive letters which are different. Swistak's method doesn't work anymore, since the word needs not anymore be itself repetitive if it contains (at least) a pair of identical consecutive letters. The thesis still holds, with just two notable exceptions: the words $aabb$ and $abba$ !
24.04.2012 19:13
But my solution can be easily upgraded to this generalization. So define $W$ as earlier, but now $W \neq 0$. Consider all possible swaps. If letters $i$-th and $i+1$-th are different say that we can do $i$-th swap. And by doing any possible swaps $W$ happens to equal $0$. By doing $i$-th swap we add $\omega^{i-1}(w_{i+1} -w_i)(1-\omega)$ to our sum, so such values are all equal for all possible values of $i$. One can observe that we can assign whatever we want to letters, so if these values are equal for any assignment, there should be only two possible symbols. If there's only one possible swap, our problem is trivial and we get $aabb$ as the only one result. So let's assume that there are more than one possible swap and that $\omega^{j-1}(w_{j+1} -w_j)(1-\omega)=\omega^{i-1}(w_{i+1} -w_i)(1-\omega)$, so an obvious consequence is $w_{j+1}=w_{i}, w_{i+1}=w_{j}, \omega^{i-j}=-1$, so there are at most 2 possible swaps and our word is of form $aa...abb...bba...aa$ where number of a's and b's are equal. One can easily check there's only one possibility $abba$ . And this also solves original problem without assuming periodity of starting word (but of course it can be solved without this ).
08.06.2012 09:07
let the word is periodic with $n$. So consider $n-th$ roots of unity and the word is $1\omega\omega^2....\omega^{n-1}\omega^{n}....\omega^{p(n-1)}$, where $\omega^{n}=1$. Now we swap $\omega^{j}$ and $\omega^{j+1}$,then it even now repetitive. Note that, $1$, $\omega$, $\omega^2$....,$\omega^{n-1}$ are distinct points of a unit circle. Then we can get $\omega^{j+1}=\omega^{nk+j}=\omega^{j}$, ($k<{p}$). $\omega^{j+1}=\omega^{j}$ ,or, $\omega^{j}(\omega-1)=0$ ,or, $\omega=1$,o.w. $\omega^{j}=0$ At last the word becomes $111....11$ ,o.w. $000...00$. So the result follows the statement is true.
13.06.2015 15:25
Is it possible to look at the repetitive form of the word, and then flip consecutive letters back in order, from the front of one block a word to the back? If so, we could match each word with the next one, as they would be the original word.
11.04.2020 11:13
Fix a word $w = w_1w_2 \cdots w_n$, which has the first property but not the second (for the purpose of contradiction). Call a swap $s$ which changes $w$ an impactful swap; let the result of $w$ after the swap $s$ be denoted $s(w)$ (which is itself a word). Call a word drab if it is just repetitions of a single letter. Let the period $p(x)$ for any word $x$ be the smallest integer $p$ for which we can concatenate $p$ identical words and have $x$. One can show using Bezout that if we can concatenate words of length $k$ to form $x$ then $p(x) \mid k$. Also define the length $\ell(x)$ as obvious; $\ell(w) = n$. Define the $r(x)$ to be equal to $\ell(x)/p(x)$, the length of the sub-words. Finally, for a word $x$, define $\overline{x}_1, \overline{x}_2, \ldots, \overline{x}_{p(x)}$ to be the $p(x)$ subwords of length $r(x)$. Define the diversity $d(x)$ of a word $x$ to be the number of impactful swaps in $x$ + 1, which is also equal to the number of drab words that partition $x$. Claim 1. For any impactful swap $s$, $d(s(x)) \ge d(x) - 2$, with equality if and only if $s(x)$ swaps the middle $ab$ in a word $baba$. Proof. Suppose that the two letters $s$ swaps are $a$ and $b$, and the letter before $a$ is $c$, and the letter after $b$ is $d$. The rest of the word remains unchanged so the difference $d(s(x)) - d(x)$ is equal to the difference $d(cabd) - d(cbad)$, and the first is at most $3$, and the second at least $1$ since $b \ne a$, and it is $1$ only when $c = b$ and $d = a$. $\square$ Claim 2. For any repetitive word $x$, if $d(x) > 1$ then $d(x) \ge 2p(x)$, with equality if and only $d(x)$ is of the form $uvuv \ldots uv$, repeats $p(x)$ times, where $u$ and $v$ are words. Proof. Consider $\overline{x}_i$; if the last letter is equal to the first, then the number of drab words that partition $x$ is equal to $p(x) \cdot d(\overline{x}_1) - p(x) + 1$. It is impossible for $d(\overline{x}_1) = 2$ since it begins and ends on the same letter, so $d(x) \ne p(x) + 1$. If the last letter is not the same as the first, then $d(x) = p(x) \cdot d(\overline{x}_1)$. We cannot have $d(\overline{x}_1) = 1 \implies d(x) = 1$, so $d(x)$ is at least $2p(x)$, with equality when $d(\overline{x}_1) = 2$. $\square$ Define $m(n)$ with respect to the word $w$ to be the number of impactful swaps $s$ for which $p(s(w)) = n$. Claim 3. If $k \ge 3$, $m(k) \le 1$. If $k = 2$, $m(k) \le 2$. $m(2) + m(4) \le 2$. Proof. If $k \ge 5$, observe that one swap $s$ can change at most two of the $p(s(w))$ induced subwords. Consider two swaps $s_1, s_2$, with $p(s_1(w)) = p(s_2(w))$; by pigeonhole, there must exist a subword $\overline{w}_k$ that is kept constant. Then this forces $w = s_1(w) = s_2(w)$ so we cannot have two such words. If $k = 4$, consider two different swaps $s_1, s_2$. If one of them is completely within a subword, then there will exist a subword (out of $4$ subwords total) which is kept constant, contradiction. Furthermore, one swap has to be in between the first and second subword (WLOG $s_1$), and another has to be within the third and fourth subword (WLOG $s_2$), so $w$ looks like this: $$xa ~ by ~ zb ~ aw,$$where $x, y, z, w$ are words. Yet this also means that $s_1(w) = xb ~ ay ~ zb ~ aw$, so $y$ must end with $b$, and that $s_2(w) = xa ~ by ~ za ~ bw$, so $y$ must end with $a$, and thus $a = b$ contradiction. If $k = 3$, again consider two different swaps $s_1, s_2$. If one of them is completely within a subword (WLOG $s_1$, and WLOG this is the first subword), then the other must be in between the other two subwords (WLOG $s_2$) or else there will be a constant subword (when we look at $3$ subwords partitioning $w$). Then $s_2(w)$ will look like this $x ~ yb ~ az$ where $w$ is $x ~ ya ~ bz$, so actually $w$ is of the form $$bx'a ~ by'b ~ az'a,$$where $x, y, z, x', y', z'$ are all words. But then any swap within the first subword won't change the fact that the other two subwords end in different letters, so it doesn't work. The other case is when both are between subwords, WLOG $s_1$ is in between the first and second subword and $s_2$ is in between the second and third subword. Then $w$ has to look something like this: $$xb ~ aya ~ bz,$$and $s_1(w)$ looks like $xa ~ bya ~ bz$ (so $x$ begins with in $a$) and $s_2(w)$ looks like $xb ~ ayb ~ az$ (so $x$ begins with $a$), contradiction. If $k = 2$, if we have two swaps entirely within the same subword, then the other subword is constant, contradiction (here we have $k = 2$ subwords partitioning $w$). Thus we can have at most one swap per subword and one more swap in between the subword. Suppose we have a swap $s_1$ within a subword (WLOG, the first subword) and a swap $s_2$ between subwords. Then we have something like $w = xa ~ by$ and $s_2(w) = xb ~ ay$, so $w = ax'a ~ by'b$. Then the swap $s_1$, in order to make the subwords the same, must both make the first letter of the first subword into $b$, and the last letter of the first subword into $b$, which is impossible. Therefore we can have just at most one swap within each of the two subwords and two swaps total. For the last part, note that a swap $s$ with $p(s(w)) = 4$ can actually be included as part of the argument in the last part (as it does divide $w$ into two equal subwords), so $m(4)$ should actually be included in the count. $\square$ Now consider a swap $S$ which maximizes $p(S(w))$. Suppose $p(S(w)) \ge 4$. \begin{align*} p(S(w)) - 1 &\ge 2 + 1 + \sum_{k = 5}^{p(S(w))} 1 \\ &\ge (m(2) + m(4)) + m(3) + \sum_{k = 5}^{p(S(w))} m(k) \\ &= \sum_{k = 2}^{p(S(w))} m(k) \\ &= d(w) - 1 \\ &\ge d(S(w)) - 3 \\ &\ge 2p(S(w)) - 3 \\ \end{align*}or $p(S(w)) \le 2$, contradiction.
When $p(S(w)) = 3$, the same inequality becomes $3 \ge 2p(S(w)) - 3$ or $p(S(w)) \le 3$ -- however, this is the equality case, so all of the following must hold: $m(2) = 2$, $m(3) = 1$, $d(w) = d(S(w)) - 2$; i.e. around $S(w)$, $w$ looks like $abab$, $d(S(w)) = 2p(S(w))$. By the last, we see that $S(w) = uvuvuv$ for words $u$ and $v$. By the third, we will require that $u$ and $v$ both have length $1$, and then by manual inspection we can conclude that it's impossible for $m(2) = 2$ as well. Therefore, $p(S(w)) \ne 3$, so $p(S(w)) = 2$. If $m(2) = 2$, then $w$ looks something like this: $$xaby ~ xbay.$$There must be no more possible swaps. In order for the first subword to have no more impactful swaps, $x$ is a drab word consisting only of $a$s and $y$ is a drab word consisting only of $b$s, yet in order for the second subword to have no more impactful swaps, $x$ is a drab word consisting only of $b$s and $y$ is a drab word consisting only of $a$s, which doesn't work unless $x, y$ both have length $0$. But then $abba$ doesn't work either, so this doesn't work. (If we use mavropnema's variant, this is the first edge case.) Now if $m(2) = 1$, then $w$ looks something like $$xa ~ by,$$and $S(w) = xb ~ ay$, so $w = ax'a ~ by'b$, and then $x' = y'$ so we have $w = ax'a ~ bx'b$. There must be no other swaps in either subword, so from the first subword we get that $x'$ is a drab word with only $a$s, and from the second subword we get that $x'$ is a drab word with only $b$'s, so again $x'$ must have length zero. But then $aa ~ bb$ doesn't work either, so this doesn't work (or again, for the variant, we get the second edge case). If $m(2) = 0$ there are no impactful swaps and then $w$ itself is drab. $\square$
19.09.2020 19:53
22.02.2021 21:19
21.09.2024 04:55
Solution from Twitch Solves ISL: A word with the property that swapping any two adjacent letters makes the word repetitive, but for which all letters the same, will called a unicorn. The problem asks to show there are no unicorns. So assume for contradiction there exists a unicorn. We proceed in three steps. Step 1. Reduction to binary alphabet. In the alphabet, choose one letter (that appears in the unicorn) to be $0$ and replace all the letters with $1$. The resulting word is still a unicorn on the two symbols $\{0,1\}$. In this way we only need to consider the problem for the alphabet $\Sigma = \{0,1\}$. Step 2. Unicorns are repetitive themselves. So let $w \in \Sigma^n$ be a unicorn. It's easy to see that $w = 010101\dotsm$ is not a unicorn; if we swap the first two fits, the resulting word $100101\dotsm$ has a doubled $00$ that appears only once, so it is not a unicorn. Similarly, $w = 101010\dotsm$ is not a unicorn. Hence, we may assume our unicorn $w$ has at least two adjacent bits equal. This means that $w$ is itself repetitive. Step 3. Main argument. From now on let $w[i]$ denote the $i$\textsuperscript{th} letter of $w$. Fix an index $1 \le k < n/2$ for which $w[k] \neq w[k+1]$. Let $w'$ be the word that results from swapping the unequal bits, so $w'[k] = w[k+1]$ and $w'[k+1] = w[k]$. Now $w$ is repetitive, and so is $w'$; so there should exist integers $p \le n/2$ and $q \le n/2$ dividing $n$ (the periods) such that the identities \[ w[i] = w[i+p] \quad \forall 1 \le i \le n-p; \qquad w'[i] = w'[i+q] \quad \forall 1 \le i \le n-q. \]We may assume $p$ and $q$ are different and don't divide each other. We will now produce a contradiction in two cases. Consider the case $\gcd(p,q) = 1$. Then, the number of $1$'s in $w$ ought to be a multiple of $n/p$, because $w$ consists of $n/p$ repetitions of some word. Similarly, the number of $1$'s in $w'$ ought to be a multiple of $n/q$. But these numbers are equal. So the number of $1$'s is a multiple of both $n/p$ and $n/q$. When $\gcd(p,q) = 1$, this can only occur if the numbers $1$'s is divisible by $n$, i.e.\ $w = 0 \dots 0$ or $w = 1 \dots 1$. Then $w$ is not in fact a unicorn. Otherwise, let $d = \gcd(p,q) > 1$. Choose the index $i = k$ to start. In a move we update the index as follows: If $i + p < n$, replace $i$ with $i + p$. Otherwise, replace $i$ with $i - q$. Repeat this until $i \equiv k \pmod q$ again for the first time. This process is well defined since $p$ and $q$ are different and less than $n/2$. This creates a sequence \[ k = i_0, i_1, i_2, \dots, i_m \]with the property that the values of $w$ and $w'$ at all indices except the ends are equal. (The assumption $d > 1$ means that all $i_\bullet$ are $k \pmod d$, so this sequence never contains $k+1$.) Following the chain then creates a contradiction, because we started at $w[k]$ and ended at $w'[i_m] = w'[k] \neq w[k]$ following only equalities. A cartoon is shown below for $p = 9$, $q = 6$, $n = 18$, $k = 2$. [asy][asy] size(12cm); for (int i=1; i<=18; ++i) { dot("$" + ((string)(i)) + "$", (i,0), dir(-90)); } void draw_arr(int x, int y, pen p) { draw((x,0)..((x+y)/2, (y-x)/5)..(y,0), p, EndArrow(TeXHead), Margins); } draw_arr(2,11, deepgreen); draw_arr(11,5, red); draw_arr(5,14, deepgreen); draw_arr(14,8, red); draw_arr(8,2, red); label("$w$", (0,-2), blue); label("$w'$", (0,-3), blue); draw(box((0.6,-1.6), (9.4,-2.4)), deepgreen); draw(box((9.6,-1.6), (18.4,-2.4)), deepgreen); draw(box((0.6,-2.6), (6.4,-3.4)), red); draw(box((6.6,-2.6), (12.4,-3.4)), red); draw(box((12.6,-2.6), (18.4,-3.4)), red); label("$\mathbf{0}$", (2,-2), blue); label("$\mathbf{1}$", (3,-2), blue); label("$\mathbf{1}$", (2,-3), blue); label("$\mathbf{0}$", (3,-3), blue); label("$0$", (11,-2), blue); label("$0$", (11,-3), blue); label("$0$", (5,-2), blue); label("$0$", (5,-3), blue); label("$0$", (14,-2), blue); label("$0$", (14,-3), blue); label("$0$", (8,-2), blue); label("$0$", (8,-3), blue); [/asy][/asy]