Help me to solve the codechef problem(Chef loves Diwali)

Problem link: https://www.codechef.com/problems/CHESHCYC

Help me solve this question.
How to use bit masking in this question?

Its just that 40 lights can be denoted by 40bits. You set the bit number for the light that is ON.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.