Throughout the solution, all the words are nonempty. For any word R of length m, we call the number of indices i∈{1,2,…,N} for which R coincides with the subword xi+1xi+2…xi+m of W the multiplicity of R and denote it by μ(R). Thus a word R appears in W if and only if μ(R)>0. Since each occurrence of a word in W is both succeeded by either the letter a or the letter b and similarly preceded by one of those two letters, we have
μ(R)=μ(Ra)+μ(Rb)=μ(aR)+μ(bR)(1)
for all words R.
We claim that the condition that N is in fact the minimal period of W guarantees that each word of length N has multiplicity 1 or 0 depending on whether it appears or not. Indeed, if the words xi+1xi+2…xi+N and xj+1…xj+N are equal for some 1≤i<j≤N, then we have xi+a=xj+a for every integer a, and hence j−i is also a period.
Moreover, since N>2n, at least one of the two words a and b has a multiplicity that is strictly larger than 2n−1.
For each k=0,1,…,n−1, let Uk be a subword of W whose multiplicity is strictly larger than 2k and whose length is maximal subject to this property. Note that such a word exists in view of the two observations made in the two previous paragraphs.
Fix some index k∈{0,1,…,n−1}. Since the word Ukb is longer than Uk, its multiplicity can be at most 2k, so in particular μ(Ukb)<μ(Uk). Therefore, the word Uka has to appear by (1). For a similar reason, the words Ukb, aUk, and bUk have to appear as well. Hence, the word Uk is ubiquitous. Moreover, if the multiplicity of Uk were strictly greater than 2k+1, then by (1) at least one of the two words Uka and Ukb would have multiplicity greater than 2k and would thus violate the maximality condition imposed on Uk.
So we have μ(U0)≤2<μ(U1)≤4<…≤2n−1<μ(Un−1), which implies in particular that the words U0,U1,…,Un−1 have to be distinct. As they have been proved to be ubiquitous as well, the problem is solved.