One quick question
why AC?
https://codeforces.me/contest/81/submission/177441374
shouldn't this be O(n^2)?