code for prob 16 merged