optimizing problem p4