code of problem B