Solve problem #40