Replace min/max with pairs/ranges.