Solution for Qualification Round, Problem 1.