#K39057. Sort 0-1-2 Array

    ID: 26335 Type: Default 1000ms 256MiB

Sort 0-1-2 Array

Sort 0-1-2 Array

You are given an array containing only the integers 0, 1, and 2. Your task is to sort the array in non-decreasing order. In other words, if the counts of 0, 1, and 2 in the array are \(c_0\), \(c_1\), and \(c_2\) respectively, then the sorted array should be represented as:

[ \underbrace{0,0,\cdots,0}{c_0} ; \underbrace{1,1,\cdots,1}{c_1} ; \underbrace{2,2,\cdots,2}_{c_2} ]

The input consists of multiple test cases. For each test case, you will be given an array and you must output its sorted version.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains an integer T, the number of test cases.
  • For each test case:
    • The first line contains an integer n representing the number of elements in the array.
    • The second line contains n space-separated integers, each of which is 0, 1, or 2.

outputFormat

For each test case, output a single line containing the sorted array in non-decreasing order. The elements should be separated by a single space and printed to stdout.## sample

3
5
0 2 1 2 0
3
2 1 0
7
1 0 1 0 2 1 2
0 0 1 2 2

0 1 2 0 0 1 1 1 2 2

</p>