Production of charged pions off nuclei with 3...30 GeV incident protons and pions