problem 50

accepted after consulting the solution