Dp problem from UVA.