TLE in ARC 165 task C
Hello everyone. My solution gets TLE on this problem. I have no idea what I'm doing wrong because my solution is quite similar to the one mentioned in the editorial. Can you help, please?