C2median(b4,10000-sum(b$3:b3),0)*0.45+median(sum(b$4:b4)-10000,b4,0)*0.25
try this and copy towards down