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