In a certain apartment building, residents are allowed to own exactly one dog, exactly one cat, or one dog and one cat. No other pets are allowed. There are 22 cats and 17 dogs in the building. If there are 25 apartments that contain only one dog or one cat, how many apartments, in total, contain pets?

(A) 27

(B) 32

(C) 35

(D) 39

(E) 42

Thank you. 🙂