Can anyone give the idea how to solve this problemm

https://www.codechef.com/JUNE20B/problems/TTUPLE