3. Milla was writing the letters M and L in uppercase. At the end, she counted that the letter matched the previous one 59 times, and did not match 40 times. Determine the maximum number of letters M that Milla could have written, and prove that it is indeed the maximum.


Solution. Answer: 80 letters.

For each letter except the first, it is known whether it matches the previous letter or not. Therefore, Milla wrote $1+59+40=100$ letters.

Divide all the written letters into groups of consecutive identical letters. Then, groups of M (M-groups) will alternate with groups of L (L-groups). At the beginning of each group, except the first group, there is a letter that does not match the previous letter. All other letters in the groups match the previous letter. Therefore, there are a total of $1+40=41$ groups.

If the first letter is $M$, then there will be 21 M-groups and 20 L-groups. If the first letter is L, then

![](https://cdn.mathpix.com/cropped/2024_05_06_d0509d899de4d1fd391dg-2.jpg?height=69&width=1838&top_left_y=294&top_left_x=109)

The minimum number of letters in one group is one. Therefore, Milla wrote at least $20 \times 1=20$ letters L. Thus, the number of letters M cannot be more than $100-20=80$.

It remains to show that Milla could indeed write 80 letters M. This is not difficult: first, write 60 letters M, and then 20 pairs LM.