I used logic to solve the problem.