This submission gets Time limit Exceeded with this generated input making the complexity reach $$$O(N^2*logN)$$$:
But then I obviously optimized my code and made it unhackable unhackable submission
BledDest please add the hack test mentioned above in the tests of the problem