this is the complete version of part3 of midterm