Solution for problem 21