Measurement of beauty and charm production in pp collisions at √s = 5.02 TeV via non-prompt and prompt D mesons