added code for problem 27