SDE Path

Sort 0s, 1s, and 2s

Medium

Sort 0s, 1s, and 2s

Sort an array of only 0s, 1s, and 2s (the Dutch national flag problem).

Input format

The first line has N. The second line has N integers, each 0, 1, or 2.

Output format

Print the array sorted in non-decreasing order (all the 0s, then the 1s, then the 2s).

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
5
2 0 1 2 0
Expected output
0 0 1 2 2
Example 2
Input
3
2 2 2
Expected output
2 2 2