I tried this problem: https://codeforces.com/contest/1136/problem/D.
And came up with a solution similar to the solution in the editorial.
But I first submitted my Python code in both Python3 and PyPy3 and had TLE.
But when I submitted an ALMOST equivalent code in C++, it got accepted.
I wonder what's wrong in my python code or is it the compiler's/interpreter's doing?
Python Code 1 : https://codeforces.com/contest/1136/submission/51256343.
Python Code 2 : https://codeforces.com/contest/1136/submission/51262124.
C++ code: https://codeforces.com/contest/1136/submission/51257855.
Thanks in advance.