Let E={x:f(x)=f(a)} be countable. For a closed subset C of the real line, if f(a)∈C, its inverse image contains a and is closed by definition. If f(a)∈/C, its inverse image lies inside E and is countable, hence is again closed. Every closed inverse image is therefore closed, proving f is continuous.