Solution to problem1