TLE in PERMUT2

Link to my solution : https://www.codechef.com/viewsolution/33014387
though logic is so simple and does not take much time to run on custom inputs. it exceeds the time limit. can anyone explains why that happens?