Any Body help me with this question

Question source https://www.codechef.com/ACMIND17/problems/COMPEXP
please help me and also can anybody give me sources.