For part (b), trying some simple examples should give you the formula. Then you just need to prove it is correct.