DP for steps 1,2,3