We want x lbs of 100% chocolate and (9-x) lbx of 20% chocolate, giving us 9 lbs of 50% chocolate.
x + 0.2(9-x) = 0.5(9)
x + 1.8 - 0.2x = 4.5
0.8x = 2.7
x = 3.375 lbs of the 20% chocolate to be removed from the bag, replaced with 100% chocolate
There will still be 5.625 lbs of 20% chocolate in the bag; that equates to 1.125 lbs of chocolate
1.125 lbs in the bag plus the 3.375 lbs of pure chocolate added gives us 4.5 lbs of chocolate in the 9 lbs