Some medicines are expensive for a reason: they're new and need to have R&D (and FDA) costs recovered (this is why we have patents), they have niche use and are produced in small quantities (cancer immunotherapies), they're perishable (biologicals), or all three. Many others are expensive because we have no regulatory protections against price gouging. Epi-Pens are another example. A 1mL vial of epinephrine costs ~$5, and the syringe to inject it costs pennies. Auto-injectors add some value, but not the $700 Mylan charges. They're fundamentally a pre-filled syringe a spring, and an injection molded case.
I wonder what the system would look like if we granted longer pharmaceutical patents (say, 30 years), with the change that upon expiration of the patents medicines would be produced by the government and sold at cost (or provided for free).