I couldn't find the link for editorial of that contest. I came up with some $$$\mathcal{O}(n^2)$$$ solution but couldn't improve it any further.
How to solve Problem G from Codeforces Round 513?
I couldn't find the link for editorial of that contest. I came up with some $$$\mathcal{O}(n^2)$$$ solution but couldn't improve it any further.