Conditional probability on 3 events. Say you have 3 events $A, B$, and $C$. Then you have to calculate the probability of $B$ given $A$.
The formula that the answer key states:
$$P(B|A)=P(B|A,C)P(C) + P(B|A,C^\complement)P(C^\complement)$$
I understand that for just two events $B$ and $A$ it is:
$$P(B)=P(B|A)P(A) + P(B|A^\complement)P(A^\complement)$$
How do you derive the first formula?

The first formula is true when events $A$ and $C$ are independent, which means
$$p(A \cap B)=p(A)p(B)$$
The RHS of the first formula can be written as (Bayes rule)
$$p(B|A)=\frac{p(B\cap A)}{p(A)}$$
Then, using the second formula
$$\frac{p(B\cap A)}{p(A)}=\frac{p(B\cap A|C)p(C)+p(B\cap A|C^c)p(C^c)}{p(A)}$$
$$=\frac{p(B\cap A \cap C)p(C)}{p(C)p(A)}+\frac{p(B\cap A \cap C^c)p(C^c)}{p(C^c)p(A)}$$
Now, if $A$ and $C$ are independent, we can take the final step as the following
$$=\frac{p(B\cap A \cap C)p(C)}{p(A\cap C)}+\frac{p(B\cap A \cap C^c)p(C^c)}{p(A\cap C^c)}=p(B| A \cap C)p(C)+p(B| A \cap C^c)p(C^c)$$
