partition then sort then group