Hydrodynamic simulation of the formation of protostars during molecular cloud collapse and the chemical evolution in these processes