implement problem 1 to 3