Make me understand the problem Beautiful Smriti

Help me to understand the code of the problem Beautiful Smriti.
https://www.codechef.com/IEMCO17/problems/SMRITI
the code CodeChef: Practical coding for everyone
I am totally confused, Please help me. Thanks in advance