MXFACS code drive problem, need help with TLE

In Yesterday’s code drive MXFACS solution I used map and got TLE, Please someone help why am I getting TLE. Problem link : CodeChef: Practical coding for everyone
Solution Link: CodeChef: Practical coding for everyone
I would be really grateful if someone could shed light on why is map giving TLE.