Every program you apply has a separate cost, regardless of their prelim/advanced category.
Of course applying to 20 prelimIM and 20 Derm is far cheaper that apply to 40 IM only., check this out..
https://www.residencyplace.com/ErasCalcPage.aspx , Don't look at the specialties, just put in two separate Slots how many prelims and how many advanced programs you plan to apply.