Solution (source code)

= Solution

For a finite or countable measurable partition, the <law of total probability> is
$$
\boxed{\mathbb P(A)=\sum_{i:\,\mathbb P(B_i)>0}\mathbb P(A\mid B_i)\mathbb P(B_i).}
$$
Indeed, $A$ is the disjoint union of $A\cap B_i$, and the <conditional probability> formula gives each positive-probability term. Zero-probability cells contribute zero; their conditionals need not be defined by a ratio. If all cells have positive probability, the sum simply runs over every $i\in I$.