TLE in Math Day problem

Why am I getting TLE in the last two cases?

You have messed up the link to code. Please see it.