Solution for problem 29