Ranking & Reweighting Improves Out-of-distribution Robustness