Using almost same code from hmw3, we managed to do the fourth problem easly