finish part3 of assignment4, stuck in finding the marginals