5. (7 points) The king decided to test his hundred sages and announced that the next day he would line them up with their eyes blindfolded and put a black or white hat on each of them. After their eyes are uncovered, each, starting from the last in line, will name the supposed color of their hat. If he fails to guess correctly, he will be executed. The sages still have time to agree on how they will act tomorrow. How many sages can definitely be saved?