Next Palindrome TLE

Problem Statement: http://www.codechef.com/problems/PALIN

I used the spoj wiki guide to write the code and testing out large values is giving pretty quick results(and correct according to me). However on submission I get TLE.

My Solution: http://www.codechef.com/viewsolution/6737255

Would really appreciate some help on pointing out whats wrong, including help on how accurate the code is.