Solution finalized for problem 1