Contribution of particle-particle, hole-hole and particle-hole ring diagrams to the binding energies of finite nuclei