## Task A-4.7.

A sequence of digits consists of ones and zeros. Among any 200 consecutive digits, the number of ones and zeros is equal, and among any 202 consecutive digits, the number of ones and the number of zeros differ. What is the maximum possible length of such a sequence?
## Solution.

The maximum possible length of such a sequence is 300.

Let $n$ be the length of the sequence, and let $a_{1}, a_{2}, \ldots, a_{n}$ be the digits of the sequence.

Consider any 202 consecutive digits $a_{i}, a_{i+1}, \ldots, a_{i+201}$. Since the number of ones and zeros among them is not equal, but among the digits $a_{i+2}, a_{i+3}, \ldots, a_{i+201}$ it is, we conclude that the digits $a_{i}$ and $a_{i+1}$ cannot be different, i.e., $a_{i}=a_{i+1}$ for any $i$ such that $201+i \leqslant n$.

Let the length of the sequence be $n$. From this, it follows that

$$
a_{1}=a_{2}=\ldots=a_{n-200}
$$

If we had $n>300$, the first 101 digits would be equal. However, this is not possible because among the first 200 digits, exactly 100 are equal. Therefore, we conclude that it is necessary that $n \leqslant 300$.

For $n=300$, let's construct an example of a sequence that satisfies the conditions of the problem. Let the first 100 digits be equal to 1, the next 100 digits be equal to 0, and the last 100 digits be equal to 1 again.

Since any 200 consecutive digits of this sequence contain exactly 100 ones, we conclude that among any 200 consecutive digits, the number of ones and zeros is equal. On the other hand, any 202 consecutive digits of the described sequence contain at most 100 ones and at least 102 zeros, so the second condition is also satisfied.

Therefore, the maximum possible length of such a sequence is 300.

Note: In the same way that it is proven that $a_{i}=a_{i+1}$, it can also be proven that $a_{200+i}=a_{201+i}$ for any $i$ such that $201+i \leqslant n$, and then that the last $n-200$ digits are all equal. Solutions that have these claims but did not achieve any of the last 3 points in the above scoring scheme receive an additional 1 point.