Problem 6 proper solution