50 + tw + if (n<24, if (r==1,200, if(r==2,150, if(r==3,125, if(r==4,100, if(r==5,75, if(r==6,50)))))), if(r==1,350,if (r==2,300,if (r==3,250,if (r==4,200,if (r==5,150,if (r==6,125,if (r==7,100,if (r==8,75,if (r=9,50))))))))))

This formula looks like it works to do all that you asked