During a business meeting, I was trying to find a continuous function $f:\mathbb{R}\to\mathbb{R}$ such that $|f^{-1}(\{y\})| = 2$ for all $y\in \mathbb{R}$, and after some experimentation I found $$f:\mathbb{R}\to\mathbb{R}, \, x\mapsto \log(x^2).$$
For which integers $n>2$ is it possible to find a continuous function $f:\mathbb{R}\to\mathbb{R}$ such that $|f^{-1}(\{y\})| = n$ for all $y\in \mathbb{R}$?



Continuous function $f:\mathbb{R}\to\mathbb{R}$ with fixed size finite fibers
There is no continuous function $f:\,\mathbb{R}\to \mathbb{R}$ such that $|f^{-1}(x)|=2k$ for any $x$ (here $k$ is some fixed positive integer.) 


Indeed, let $p\_1<p\_2<\ldots<p\_{2k}$ be preimages of $0$. Fix small $\delta$ so that the $4k$ intervals $(p\_i-\delta,p\_i)$ and $(p\_i,p\_i+\delta)$ are mutually disjoint. Note that if $\varepsilon>0$ is small enough, then each of them contains a preimage either of $+\varepsilon$ or $-\varepsilon$. But $+\varepsilon$ and $-\varepsilon$ have $4k$ preimages in total, therefore exactly $2k$ intervals contain preimages of $+\varepsilon$ (call them ''positive'') and $2k$ intervals contain preimages of $-\varepsilon$ (call them ''negative''). Note that the intervals $(p\_{i+1}-\delta,p\_{i+1})$ and $(p\_i,p\_i+\delta)$ are simultaneously positive or simultaneously negative, since $f$ has constant sign on $(p\_i,p\_{i+1})$. Thus by parity of the number of positive intervals we conclude that the intervals $(p\_1-\delta,p\_1)$ and $(p\_{2k},p\_{2k}+\delta)$ also have the same sign. Since $f$ preserves the sign on the rays $(-\infty, p\_1)$ and $(p\_{2k},+\infty)$, we see that $f$ must have the same sign on these rays, and therefore $f$ is bounded either from above or from below. This contradicts to surjectivity.


Ah, I just realize that this is proved by Mateusz Kwaśnicki in the comments, but slightly differently (above reasoning does not use cardinality).


