#P10901. Sorting Numbers by Enclosed Areas
Sorting Numbers by Enclosed Areas
Sorting Numbers by Enclosed Areas
In the Kingdom of Blue Bridge, the magnitude of a number is determined not only by its numerical value but also by the number of completely enclosed regions in its digits. The enclosed regions are defined as follows:
- Digits 1, 2, 3, 5, 7 have 0 enclosed regions.
- Digits 0, 4, 6, 9 have 1 enclosed region each.
- Digit 8 has 2 enclosed regions.
For instance, the number \(68\) has a total of \(1+2=3\) enclosed regions since digit 6 contributes 1 and digit 8 contributes 2.
The sorting rule is as follows:
- If two numbers have a different total number of enclosed regions, the number with fewer enclosed regions is considered smaller.
- If they have the same number of enclosed regions, the one with the smaller numerical value is considered smaller.
- If both the count of enclosed regions and their numerical values are the same, the numbers are considered equal.
You are given an integer \(n\) followed by \(n\) non-negative integers. Sort these numbers in ascending order according to the Blue Bridge Kingdom rules and output the result.
inputFormat
The first line contains an integer \(n\) indicating the number of values.
The second line contains \(n\) non-negative integers \(a_1, a_2, \dots, a_n\) separated by spaces.
outputFormat
Output the sorted numbers in one line, separated by spaces.
sample
3
41 18 68
41 18 68