For: $(X,d)$ is a metric space, $f:X\to X$ is a continuous function and $g:X\to R, x\mapsto g(x)=d(f(x),x)$. Prove that $g$ is a continuous function.
Definition: $f$ is continuous at $x_0$ if only if $\forall\epsilon>0,\exists \delta >0 : \forall x: d(x-x_0)<\delta : d(f(x),f(x_0))\le \epsilon. $
Hint $1$: If $g\colon Y\to Z$ and $h\colon Y\to Z'$ are continuous functions, then $j\colon Y\to Z\times Z'$ given by $j(x)=(g(x),h(x))$ is continuous (prove this if you haven't been shown this result before).
Hint $2$: If $a\colon A\to B$ and $b\colon B\to C$ are continuous functions, then their composition $b\circ a\colon A\to C$ is a continuous function.
Hint $3$: If $d\colon M\times M\to\mathbb{R}$ is a metric, then $d$ is a continuous function on the space $M\times M$ with the product topology induced by the metric on $M$.