Getting run time error on test 9. Need help debugging

Continuing the discussion from Codeforces Round #635 (Div. 2) Problem C (Need Help):

Any leads from anyone? I thought it could be due to recursion limit but it’s not.
Tried a more simple approach as well but still run time error on the same test : Submission #77047258 - Codeforces

I’ve really got no clue since I don’t even know what kind of exception it might be throwing. This is so weird.