My code giving wrong ans, why?

i simply took every word and checking whether it is present or not.