Accretion, loss, and fractionation of martian water