problem: https://www.codechef.com/MAY20B/problems/CHANDF my solution: https://www.codechef.com/viewsolution/33192492