Solution (source code)

= Solution

The good and defective cases are disjoint and exhaustive. The <law of total probability> therefore gives
$$
\boxed{P(x_0)=pg_0+(1-p)d_0.}
$$