Getting different verdict for same code , please check

problem : Contest Page | CodeChef

my first submission (AC) : Solution: 54572101 | CodeChef
my second submission (TLE) : Solution: 54572123 | CodeChef

Both of my solutions are same code in python but I get a AC in one whereas I get a TLE in another . Why does this happen ?