Sequential version of HW2 Q5.