Isn't @stefanv 's suggestion also n^2 ?