I am trying to solve 611D - New Year and Ancient Prophecy, I wrote 60357814 this solution. I think the Time Complexity of my solution is $$$O(n ^ 2\log{}n)$$$ but I am getting Time Limit Exceeded verdict. I want to know is my Time Complexity analysis is wrong or only $$$O(n ^ 2)$$$ solution will pass.