chef and dolls problem showing wrong answer

can anyone explain my mistake in this…
https://www.codechef.com/viewsolution/8388261