solution of the second problem