TLE in CHEFSHIP

How does this O(N) complexity code give runtime error?
https://www.codechef.com/viewsolution/33318435