Solution (source code)

= Solution

Using the differentiated <geometric series>,
$$
\boxed{S_{AB}=2p\sum_{n=1}^{\infty}nq^{n-1}
=\frac{2p}{(1-q)^2}=\frac2p.}
$$
This is finite for $p>0$, equals two when every visit succeeds, and diverges as the chance of success tends to zero.