TITLE: Can a surjective continuous function from the reals to the reals assume each value an even number of times?
QUESTION [22 upvotes]: Suppose $f: \mathbb{R} \rightarrow \mathbb{R}$ is continuous and onto.
Is it possible for $f$ to assume each of its values an even number of times?
To clarify, some values might be taken 2 times, some 4, some 6, etc., but always an even (and therefore finite) number.
I don't require that there be a value that is assumed any particular number of times. 
For example, the function might never take on any value exactly twice.
Here
is a closely related question with an excellent answer.

REPLY [15 votes]: This is impossible.  Suppose that $f:\mathbb{R}\to\mathbb{R}$ is such that the preimage of every point contains an even number of points.  There are only countably many points in $\mathbb{R}$ that are either local minima or local maxima of $f$ (since for each one, we can choose an interval with rational endpoints on which it is the unique global maximum/minimum).  It follows that there exists some $a\in \mathbb{R}$ such that none of the preimages $x_1<x_2<\dots<x_n$ of $a$ are local minima or local maxima.  That is, $f(x)-a$ changes sign at each $x_i$.  Since $n$ must be even, it follows that $f(x)-a$ has the same sign on all of $\mathbb{R}\setminus [x_1,x_n]$.  Since $f$ is bounded on $[x_1,x_n]$, it follows that $f$ is either bounded below or bounded above (depending on which sign it has on $\mathbb{R}\setminus [x_1,x_n]$).
(This argument is borrowed from this nice partial answer to a near-duplicate of your previous question.)