R&B: Domain Regrouping and Data Mixture Balancing for Efficient Foundation Model Training