Mitranov I.V.

The King decided to reward a group of $n$ sages. They will be placed in a row, all facing the same direction, and a black or white hat will be placed on each of them. Each sage will see the hats of all those in front of them. The sages will take turns, from the last to the first, naming a color (white or black) and a natural number of their choice. At the end, the number of sages who named the color matching their own hat will be counted: the group will receive a bonus for exactly that many days. The sages are allowed to agree in advance on how to answer. However, the sages know that exactly $k$ of them are insane (who exactly is unknown to them). An insane sage will name a white or black color and a number regardless of the agreement. What is the maximum number of days with a bonus that the sages can guarantee for the group, regardless of the position of the insane in the queue?