problem 45

accepted after consulting the solution