Production of deuterons and tritons in high-energy proton and pion interactions with emulsion nuclei