AMSGAME2 : Two exact same solutions, C++ -> AC while Python -> TLE? Any idea?

Two exact same solutions of AMSGAME2 one in Python (link) and another in C++ (link), Python solution leads to TLE while C++ solution gets AC.

Why so? Is it the matter of taking input in Python or some other reason?

I looked up here for all python submissions but there isn’t a single AC solution yet.

Python is interpreted while C++ is compiled. Naturally, Python is slower.

PS: This is just one reason. There are loads more (which I do not know), that makes Python incredibly slower compared to C++.

yea, but Python has thrice the time C++ has on codechef judge. I normally use Python and never faced such a trouble before on any question (that I’ve solved yet), other than AMSGAME2.

Few bottlenecks could be the use of raw_input and input(). You could rather use stdin.readline().split() or methods from stdin library which are little faster. I don’t other optimizations that can be done in the code (and not the logic). You are already using xrange than range which is recommended.

yup, I tried that already :slight_smile:
didn’t work though.