speed up mass_dist with cumsum