Hint 4.2.7.1.

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

in-context