Can $ f\colon \mathbb{R}^k \to \mathbb{R}^n$ such that $ \forall y \in \operatorname{im}(f)$, $f^{-1}(y) = \{a_y,b_y\} $ be continuous? This is the problem we want to solve:

Can $f\colon \mathbb{R}^k \to \mathbb{R}^n$ such that $ \forall y \in \operatorname{im}(f)$,   $ f^{-1}(y) = \{a_y,b_y\}, a_y \neq b_y $ be continuous?

Originally I've seen this question on an exam but it was stated only for the case $ k = n = 1 $ and $f$ surjective, which made it really easy to show $f$ can't be continuous, by using the Weierstrass extreme value theorem. A very similar argument seem to work for any $k$, as long as $n=1$. However, for general $k$ and $n$ this seems much harder. I don't see how surjectivity affects this problem, so I've dropped this assumption for now. Edit:Slup commented below, showing the relevance of surjectivity for this question.
Induction on $n$ and looking at projections of $f$ onto individual coordinates seemed tempting at first, but the composition of $f$ with a projection seems to lose any traces of the property that the inverse image of a point = exactly two points, so I don't see how this could be useful.
Trying to visualise this for $k=n=2$, it intuitively seems that in order to transform the space in this way, we would have to 'tear' it along some curve. For bigger $k = n$, that becomes 'tearing' along some $n-1$ dimensional manifold, but that's obviously completely informal, sort of useless and I completely have no idea how this idea could be translated into a formal proof.
Bonus question: Does the answer or the proof change in a significant way if we limit the domain to $ f:\overline{\mathbb{B}^k} \to \mathbb{R}^n $? We operate on a compact ball now, so that's fairly different from $\mathbb{R}^k$.
 A: I did not read the paper of Mioduszewski mentioned in one of the posts. I only
have some partial answers when $f$ is more regular than continuous. 
If $k\leq n$ and $f:\overline{B}\rightarrow\mathbb{R}^{n}$ (the bonus
question) is Lipschitz continuous, then using the area formula for Lipschitz
functions (it's in the book of Evans and Gariepy "Measure theory and fine
properties of functions")
$$
\infty>L\mathcal{L}^{k}(\overline{B})\geq\int_{\overline{B}}Jf\,dx=\int
_{\mathbb{R}^{n}}\mathcal{H}^{0}(\overline{B}\cap f^{-1}(\{y\})\,dy=\int
_{\mathbb{R}^{n}}2\,dy=\infty,
$$
which is a contradiction. Here, $Jf$ is the Jacobian of $f$, $L$ is the bound
of $Jf$, and $\mathcal{H}^{0}$ is the counting measure. If $f:\mathbb{R}%
^{k}\rightarrow\mathbb{R}^{n}$ is Lipschitz continuous and $Jf$ has finite
integral, you get the same contradiction.
If $k>n$ and $f\in C^{k+1-n}(\mathbb{R}^{k})$, then using Sard's theorem
https://en.wikipedia.org/wiki/Sard's_theorem the set of points $\{x\in
\mathbb{R}^{k}:\,Jf(x)=0\}\cap f^{-1}(\{y\})$ is empty for $\mathcal{L}^{n}$
a.e. $y\in\mathbb{R}^{n}$. Hence, if $f$ is onto or if $f(\mathbb{R}^{k})$ has
positive measure, then taking $y\in f(\mathbb{R}^{k})$ such that
$\{x\in\mathbb{R}^{k}:\,Jf(x)=0\}\cap f^{-1}(\{y\})=\emptyset$, we get that
$Jf(x)$ has rank $n$ and so we can apply the implicit function theorem to
conclude that $f^{-1}(\{y\}$ is locally the graph of a function. In particular
$f^{-1}(\{y\})$ cannot consists of two points.
A: A negative answer for the case $k>n=1$.
Let $a,b\in\mathbb R^k $ be twin points. Let $c$ and $d $ other points. Take a path from $a $ to $c $ to $d $ to $b $. By the mean value theorem the twin points are extremal on that path. Say they are minima. This remains true even if we change the point $d $ to be any point; therefore $a $and $b $ are global minima. Since this is true for any pair of twins, any such pair are extremal. But this impossible because $ \mathbb R^k$ contains more than 4 points. 
The same argument holds for the closed ball.
A: (I'm assuming $f$ is surjective). Let $n=k=2$, $y \in \mathbb{R}^2, a_y=a, b_y=b.$ Consider the line between $a$ and $b$, $r$. This splits $\mathbb{R}^2$ in $2$ connected components, $P_1$ and $P_2$. Since these are connected, if $f$ was continous then their images through $f, Q_1$ and $Q_2$, would be connected as well, and their intersection would be empty. Since $r$ is also connected, its image $s$ is connected as well, and it contains $y$. Furthermore, since $f(a)=f(b)=y, s$ is not injective, in fact it splits $\mathbb{R}^2$ in at least $3$ connected components. Since continous functions can only decrease the number of connected components, we have a contradiction. 
For a general case with $k=n$ i think it suffices to take an adequate number of points in order to split the domain and codomain and use a similar reasoning (eg for $k=n=3$ take two points such that their preimages are coplanar and split $\mathbb{R}^3$ using a plane and a weird surface). I also think this reasoning, if a bit modified, works for $k>n$ as well (eg if $k>n=1$, it's even simpler: $\mathbb{R}^k - \{a, b\}$ is connected but its image $\mathbb{R} - \{y\}$ is not, so $f$ is not continous).
