I am getting a TLE on spoj

for this code of mine https://ide.codingblocks.com/s/246800