implement problem 1 to 4