Solution (source code)

= Solution

For independent attempts, measuring after each application of $A$ produces a success with probability $p$. Recognize the answer with the verifier and restart on failure. The number $T$ of attempts has a <geometric distribution>, with $\Pr(T=k)=(1-p)^{k-1}p$. Summing the tail probabilities gives
$$
\boxed{\mathbb E T=\sum_{k=0}^\infty(1-p)^k=\frac1p.}
$$
This counts applications of $A$; it presumes $p>0$ and a fresh preparation for each attempt. If $p=0$, neither repetition nor the amplification construction can create a good component from this input.