Subsurface water and clay mineral formation during the early history of Mars