Implementation of Problem 1