acid rain forms when sulfur dioxide and nitrogen oxides are chemically transformed in the atmosphere into sulfuric or nitric acids , sometimes carried hundreds of miles in the air , and return to earth in rain or snow .