Code for problem1