Recently I was solving this question in python. I had thought of a solution and I tried submitting it in python 3, although most of my solutions were accepted via python 3 interpreter. This problem held me by TLEs, a bunch of them.
I was so confused that I started breaking the logic in further if else's only to find that they don't help. I started to search for reasons on the internet and stumbled upon this article just by luck.
It is a TLE saviour. I skimmed through the article and submitted my code in pypy 3 instead of python 3 and to my surprise, it got Accepted. My amusement didn't end here. The execution time was very much comparable to the c++ code and almost 5 times faster than python 3.
So I am switching to this interpreter now. And if you too are getting TLEs it is would be worthy to try submitting your code with pypy 3.
Happy Coding!!!
Edit1:
Looks like pajenegod has a valid point here, this is not always true.
My apologies!!!
Edit 2:
Codeforces submission page also recommends using PyPy.
So, it's a recommendation rather than a guarantee.
It Will be more better if You will switch to C++.
Ya pypy3 saves u from tle but sometimes even pypy3 will give u tle and python3 will give u ac like in a question involving dfs or string manipulation stuff ..
Oh, any examples?
There is no guarantee that PyPy is faster than CPython. PyPy's JIT is really frail and can sometimes mess up big time. A basic example would be something like this
This runs in 3 s with PyPY3, and 2 s with CPython3. But if you change
j%6
toj%5
PyPy3 runs in 0.1 s.Yet another proof why PyPy's JIT is confusing as f**k: that exact code runs faster when you add a stupid loop doing nothing. try the following code.