Erosion and Accretion by Cratering Impacts on Rocky and Icy Bodies