Function with a set number of pre-images Let $A,B\subset\mathbb{R},n\ge2$.
Let $f:A\to B$ (not necessarily continuous) such that $\forall a\in A,f^{-1}(a)$ is a tuple of $n$ elements.
I know that if $f$ in continuous, for $A=B=\mathbb{R}$ and $n=2$, such a function does not exist. Therefore I was wondering : 
When does such a function exist ? When it does, can one give an explicit formula for such a function ?

I'm taking $A=B=\Bbb R$ here. Following your intermediate value theorem proof that no continuous function exists for $n=2$, you can prove similarly that none exists whenever $n$ is even. However, you can easily construct continuous functions for any $n$ odd. Although I've always done so graphically, I'm sure that you could find explicit formulas.
