Code giving TLE on SPOJ

Hi, I wrote code for this Question, it seems to be correct but it is giving TLE on SPOJ. Please help

code : https://ideone.com/EupRVh

@sarthakbuddy
Your code is perfect
SPOJ often shows TLE for even a 0.01 second delay
Since your code is correct and completely optimised I request you to move on to other questions and not worry about SPOJ

You can close the doubt if you dont need any other help with the code

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.