Naive reduce with cost_dx and cost_dy