Sorting based on the numbers of 0's, 1's and 2's only and rearging them