added the solution for question1,2,3,4 get stuck with the balance algorithm sigh