Hi, you are getting TLE issue, which means you need to reduce the number of operation and that can be done in this loop:
if(d>10):
for i in range (d-10):
a=a*3
Here in this loop, when value of a(infected people on that day) becomes greater than n(total population) we can simply break out of the loop because the entire ChefLand is now infected and there’s no more people to infect so, any iteration after this will be useless.