This Question is from foundation CCDSAP from binary search:
My solution: https://www.codechef.com/viewsolution/22866957