Surjection iff Right Cancellable/Sufficient Condition/Proof 2

Proof
Let $f: X \to Y$ be a right cancellable mapping.

Let $Y$ contain exactly one element.

Then by definition $Y$ is a singleton.

From Mapping to Singleton is Surjection it follows that $f$ is a surjection.

So let $Y$ contain at least two elements.

Call those two elements $a$ and $b$, and we note that $a \ne b$.

We define the two mappings $h, k$ as follows:
 * $h: Y \to Y: \forall x \in Y: h \left({x}\right) = \begin{cases}

x & : x \in \operatorname{Im} \left({f}\right) \\ a & : x \notin \operatorname{Im} \left({f}\right) \end{cases}$


 * $k: Y \to Y: \forall x \in Y: k \left({x}\right) = \begin{cases}

x & : x \in \operatorname{Im} \left({f}\right) \\ b & : x \notin \operatorname{Im} \left({f}\right) \end{cases}$

It is clear that:
 * $\forall y \in X: h \left({f \left({y}\right)}\right) = f \left({y}\right) = k \left({f \left({y}\right)}\right)$

and so:
 * $h \circ f = k \circ f$

But by hypothesis, $f$ is right cancellable.

Thus $h = k$.

Suppose $Y \ne \operatorname{Im} \left({f}\right)$.

Then:
 * $\operatorname{Im} \left({f}\right) \subset Y$

That is:
 * $\exists x \in Y: x \notin \operatorname{Im} \left({f}\right)$

It follows that:
 * $a = h \left({x}\right) = k \left({x}\right) = b$

But we posited that $a \ne b$.

From this contradiction we conclude that:
 * $Y = \operatorname{Im} \left({f}\right)$

So, by Surjection iff Image equals Codomain, $f$ must be a surjection.