problem 40 solved

after consulting the answer. Cause the problem is too tricky.