triangle, dp, inplace replacement