2 out of 3 property for homotopy This question was asked in my class of topology and I am not able to make any significant progress on it.

Let $f: X \to Y$ and $ g: Y \to Z$ be two continuous maps. Prove that if any two maps among $f, g$ and $ g\circ f$ are homotopy equivalences, then so is the third map.

Attempt: Homotopy equivalences is an equivalence relation. So, if f and g are homotopy, then $g \circ f$ is also a homotopy. This is Case 1.
But I can't use this property to  prove Case 2: If $ f$ and $ g\circ f$ is homotopy, then so is $g$ or Case 3 : If $ g$ and $g\circ f$ is homotopy, then so is $f$.
I am not able to think what result should I use to arrive at what is asked.
Can you please outline a proof?
 A: Here is a sketch/outline for how to prove this theorem. If you need more help/guidance, I can give you further tips.
First try to prove, that the compositions of homotopic maps is homotopic:
Lemma: If $f_1\simeq f_2$ (write down a homotopy) and $g_1\simeq g_2$ (write down a homotopy), then $g_1\circ f_1\simeq g_2\circ f_2$ (can you construct a homotopy out of the two other ones?).
Since $\simeq$ being an equivalence relation (whose properties don't include being compatible with composition) doesn't directly show, that the composition of homotopy equivalences is one as well, I will now go over that case:
$f$ and $g$ are homotopy equivalences $\Rightarrow$ $g\circ f$ is a homotopy equivalence.
If $f$ has a homotopy inverse $a\colon Y\rightarrow X$ (write down both conditions) and $g$ has a homotopy inverse $b\colon Z\rightarrow Y$ (write down both conditions), can you find a homotopy inverse for $g\circ f$? Use the upper lemma and precompose or postcompose a suitable of the four maps to a suitable of the four conditions. (For extra help, draw a diagram with $X$, $Y$ and $Z$ and the four maps between them.)
You do the exact same for the other two cases. If you need one example for reference:

 Assume $g\circ f$ is a homotopy inverse, then there is a homotopy inverse $c\colon Z\rightarrow X$, for which in particular $c\circ g\circ f\simeq\operatorname{id}_X$ (only one of two conditions!).
 Assume $f$ is a homotopy inverse, then there is a homotopy inverse $a\colon Y\rightarrow X$, for which in particular $f\circ a\simeq\operatorname{id}_Y$ (only one of two conditions!).

 Using the upper lemma, we precompose the first condition with $a$ and use the second condition to get $c\circ g\simeq c\circ g\circ f\circ a\simeq a$. Using the upper lemma again, we postcompose this condition with $f$ to get $f\circ c\circ g\simeq f\circ a\simeq\operatorname{id}_Y$. This means that $g$ has a left homotopy inverse (only one of two conditions!). Can you now fill in the rest?

