THE last person can see 19 hats in front of him. 19 is an odd number. So it is the sum of an even and an odd number. Let us assume that there are 12 black and 7 red hats. The Last man will say the color of the hat of which there are even numbers, in this case black.
The person in front of him can count the number hats he sees.
CASE 1 - He is wearing a red hat. So he sees 12 black hats and 6 red hats. Since he knows that black hats are in even numbers. He discovers that he's wearing a red hat.
CASE 2_ HE is wearing a black hat. So he sees 11 black and 7 red hats. The last guy has told that black hats are in even numbers.
So he discovers that he is wearing a black hat.
Similarly the people in front can find out the color of their hat and thus can save themselves.
The last man can either be wearing a red or a black hat. So that is 2 possibilities and he says one color. So he has a 50% chance to live.
THANK YOU