the rates at which they can solve problems are combined
$$rate_{Beth}=\dfrac p 2 ~\mbox{problems/hr}$$
$$rate_{Molly}=\dfrac x h~\mbox{problems/hr}$$
$$rate_{both}=\dfrac p 2 + \dfrac x h = \dfrac {p h + 2 x}{2h}$$
the time it takes for both of them to do 400 problems is 400 divided by their combined rate.
$$t_{both}=\dfrac {400}{rate_{both}}=\dfrac {800h}{ph + 2x}$$
.