Solution (source code)

= Solution

Use the centered <Hardy-Littlewood maximal function>
$$
M\theta(x)=\sup_{r>0}\frac1{2r}
\int_{x-r}^{x+r}\theta(t)\,dt.
$$
If $x>0$, choosing $0<r<x$ makes the whole interval lie in the positive half-line, so $M\theta(x)=1$. If $x=0$, every centered interval has exactly half its length in the positive half-line, so $M\theta(0)=1/2$.

If $x<0$, the average is zero for $r\leq-x$. For $r>-x$, it is
$$
\frac{x+r}{2r}
=\frac12+\frac{x}{2r}<\frac12,
$$
and these values tend to $1/2$ as $r\to\infty$. Hence
$$
M\theta(x)=
\begin{cases}
1,&x>0,\\
\frac12,&x\leq0.
\end{cases}
$$
For the uncentered maximal-function convention, intervals extending arbitrarily far to the right make the supremum equal to $1$ at every $x$.