So there are 2 1-5= 16 people who did the wrong chemistry problem but did the right physics problem.
These people must be included in the 40 people who did the right physics questions.
Then deduct 16 people who did the wrong chemistry problem, and the remaining 40- 16=24 people are completely correct.