1. [5] On an island, there live knights, liars, and yes-men; each knows who everyone else is. All 2018 inhabitants were lined up and asked to answer "Yes" or "No" to the question: "Are there more knights than liars on the island?". The inhabitants answered in turn, and everyone could hear their answers. Knights answered truthfully, liars lied. Each yes-man answered the same way as the majority of those who answered before him, and if the number of "Yes" and "No" answers was equal, he gave either of these answers. It turned out that there were exactly 1009 "Yes" answers. What is the maximum number of yes-men that could be among the inhabitants of the island?

(M. Kuznev)
Answer: 1009 yes-men. Solution: Let's call knights and liars principled people.

Estimate. First method. (Buchaev Abdulqadir) We will track the balance - the difference between the number of "Yes" and "No" answers. At the beginning and at the end, the balance is zero, and with each answer, it changes by 1. Zero values of the balance divide the row of residents into groups. Within each group, the balance retains its sign. Yes-men always increase the absolute value of the balance. Therefore, to make the balance zero, there must be no fewer principled people than yes-men. This is true for each group, and therefore for all the island's residents.

Second method. A yes-man could not increase the minimum of the current number of "Yes" and "No" answers. Since this minimum increased from 0 to 1009, and with each answer, it changed by no more than one, there must be at least 1009 principled people.

Example. First, all 1009 yes-men said "No," and then 1009 knights said "Yes."

Note. Any sequence of 1009 principled people can be thinned out by yes-men so that the condition is met.