GRUBAN Codechef.. How to solve it? Explaination Needed

Link - https://www.codechef.com/PLIT2020/problems/GRUBAN