Solution for the problem