Solution for problem 5

Sorry for such boring descriptions.