Finished the third problem for the competition