Cooling by sorting