In a survey of 400 students, 80% said they had math homework every night. Of these, 40% had writing homework every night. How many students had both math and writing every night?
A. 50
B. 128
C. 160
D. 320