I have solved this problem. I modified the previous requirements to make the teacher's classes as much as possible all in the morning or all in the afternoon.