I am getting RE in the question on test case 12. Can anyone give a test case or some insights on what might be causing the issue. Link of submission
EDIT: setting limit recursion to 100000 gave stack exhaustion error in pypy3, but worked in python3. I have no idea why this occurred.