Solving first part of 4th problem.