Solve problem 5 (naive)
Proper solution of Problem 5