Knop K.A.

The re-attestation of the Council of Sages happens as follows: the king lines them up in a single column and puts a cap on each one, either white, blue, or red. All sages can see the colors of the caps of all the sages in front of them, but they cannot see the color of their own cap or those of the sages behind them. Once a minute, one of the sages must shout out one of the three colors (each sage shouts out a color only once).

After this process is completed, the king will execute each sage who shouted out a color different from the color of their cap.

On the eve of the re-attestation, all one hundred members of the Council of Sages agreed and came up with a plan to minimize the number of executions. How many of them are guaranteed to avoid execution?
All 100 sages cannot be guaranteed to survive since no one among them can see the color of the last sage's hat.

Let's show how 99 sages can be saved. We will assign the numbers 0, 1, and 2 to the white, blue, and red colors, respectively. In the first minute, the sage standing at the back should shout out the color corresponding to the remainder of the division by 3 of the sum of all numbers assigned to the colors of the hats of the sages standing in front. Then, the sage standing directly in front of him can calculate the color of his own hat, as he can see the hats of all 98 sages standing in front; he should shout out this color in the second minute.

In the third minute, the sage standing 98th in the line calculates, based on the information from the two previous shouts and seeing the hats of 97 standing in front, the color of his own hat, shouts it out, and so on.

## Answer

99 sages.