problem 36 and 39
problem 36