Production of charged pions, kaons, and (anti-)protons in Pb-Pb and inelastic pp collisions at sNN=5.02 TeV