solves problem 3